I am writing a DLL (MS VS13, c++) that is called by an external program and which uses a standardized parameter list:
extern "C" __declspec(dllimport) int TYPE850(double &time, double xin[], double xout[], double &t, double &dtdt, double par[], int info[], int icntrl);
The results of the routine are written into the xout[] array so that the calling program can read and process the results of the DLL.
Now I want to add a dialog to the DLL that can take user input each time the DLL is called. The idea is to use MFC. It turned out that it is not easy to simply add some MFC code to the existing DLL code, so I am trying to do it the other way round: I am creating a regular MFC DLL plus a dialog resource and add the original DLL code. The code then looks like this (without the include-statements):
BEGIN_MESSAGE_MAP(CType850LibApp, CWinApp)
END_MESSAGE_MAP()
CType850LibApp::CType850LibApp()
{
}
CType850LibApp theApp;
BOOL CType850LibApp::InitInstance()
{
CWinApp::InitInstance();
CSelDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
return FALSE;
}
extern "C" __declspec(dllexport)int TYPE850(double &time,double xin[], double xout[], double &t, double &dtdt,double par[],int info[], int icntrl)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
//DLL code ...
return 1;
}
I have added the instance of the dialog to CType850LibApp::InitInstance() only for testing. The code can be compiled and when running the main application the dialog appears when the DLL is called. But the obvious problem is that the C function is never called. The idea was to call the C function within CType850LibApp::InitInstance() but that does not work because the parameter list of the function is then unknown.
So the questions are: 1) How can I call the C function with the correct parameter list so that all the information contained in the parameter list is correctly transferred to the DLL code and the results can be correctly written in the xout[] array? 2) Once I can call the C function, how can I instantiate the dialog within the DLL?
Thanks for your help!
InitInstance
, put it inTYPE850(...)
– Barmak ShemiraniInitInstance
is returningTRUE
. It's a simple function call. Edit your question to show your 2nd attempt and show relevant error message. – Barmak Shemirani