how to write an dll that's used both for c and c++ project.
first, the dll side,write down these code
// DLL Header file...
#ifdef __cplusplus
#define EXPORT extern "C" __declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
EXPORT int LoadDialog();
// DLL Implementation file...
EXPORT int LoadDialog()
{
return DialogBox(g_hDllInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);
}
LRESULT CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
...
}
then the client side to use it.
// Calling program...
#include <windows.h>
typedef VOID (*MYPROC)(VOID);
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, PSTR pCmdLine, int iCmdShow)
{
HMODULE hLib;
MYPROC theFunc;
hLib = LoadLibrary("dialog.dll");
if (hLib)
{
theFunc = (MYPROC) GetProcAddress(hLib, "LoadDialog");
if (theFunc)
{
theFunc();
}
FreeLibrary(hLib);
return 0;
}
that's all
浙公网安备 33010602011771号