1
votes

I am trying to build a very simple DLL file which supports MFC. I use VS2010.

All the examples I found on the net shows how to export class function members.

But my client, at the end, should be a C program. Meaning, it doesn't know to use classes and objects. I just need to export some simple functions for it.

What I did until now is to put the following on my dll cpp file:

extern "C" __declspec(dllexport) CString SayHello (CString strName){
    return theApp.SayHello(strName);
}

and on the app class I wrote:

CString CMyDLLApp::SayHello(CString strName){
    return (CString)"Hello " + strName; 
}

I created a simple dialog based app, which was suppose to use this function like this

CString strResult = SayHello(m_edit);

After I included the DLL h file at the top of the file:

#include "..\MyDll\MyDll.h"

But the compiler says : error C3861: 'SayHello': identifier not found

Can you please guide me how to do it? Don't offer me to not to use MFC on my DLL because I want to use the DB classes of it.

Also, how to tests it? I don't care if the test program itself is MFC based as well.

1
You need to include the DLL in the project, and import classes for it. MS has a tutorial for that. Just google "C++ using DLL"Paweł Stawarz
I hope your C Program isn't going to try and consume that function that returns a CString.Moo-Juice
Thanks guys.Moo, no it doesn't/dushkin
Moo, no it does't :-) I am just in the stage of trying to understand the concept.dushkin
In addition to #include'ing the header, you also need to import the lib. Easiest way is to add #pragma comment(lib, "MyDll.lib") in the same place you do the include.Roger Rowland

1 Answers

0
votes

Try this declaration in your app to get rid of the compiler error:

extern "C" __declspec(dllimport) CString SayHello (CString strName);

But you cannot get theApp directly from within the DLL. Add another DLL function to pass a pointer to theApp to the DLL.