-
DLL problem
Im making a dll in visual c++7. I have an exported class, which looks like this:
class RTDLL RTWindow
{
public:
void CreateWin();
};
the RTDLL is:
#ifdef USEDLL
#define RTDLL __declspec(dllimport)
#else
#define RTDLL __declspec(dllexport)
#endif
The dll compiles. But the problem is that when i try to use the dll (of course putting USEDLL in the precompiler textbox in the project settings), and run the application, it tells me that it cant find the entry point for the CreateWin function in the dll.
My application looks like this:
RTWindow win;
int main()
{
win.CreateWin();
return 0;
}
Any ideas how to sovle this problem? I tried using a def file, but it doesnt solve it, since i use __declspec. help please!!
-
Try prefixing the function with the __declspec() instaead of the whole class
-
You mean try to export just a function, right? Ive tried it. Didnt work, the same error.
-
This is my whole dll code:
-----------------------------------
globals.h
Code:
#ifndef _RTGLOBALS_H_
#define _RTGLOBALS_H_
//safely release/delete objects
#define RELEASE_(p) { if(p) { (p)->Release(); (p)=NULL; };};
#define DELETE_(p) { if(p) { delete (p); (p)=NULL; };};
#ifdef USERT
#define RTDLL __declspec(dllimport)
#else
#define RTDLL __declspec(dllexport)
#endif
//version
#define RT_VERSION "0.2"
#endif
rtwindow.h
--------------------
Code:
#ifndef _RTWINDOW_H_
#define _RTWINDOW_H_
#include <windows.h>
#include "globals.h"
typedef struct RTWinS
{
HWND hWnd;
HINSTANCE hInst;
int iWidth;
int iHeight;
int iBPP;
bool gFullscreen;
}RTWinS;
//the base window class
class RTDLL RTWindow
{
public:
RTWinS winstruct;
void CreateWin (HINSTANCE hInstance, char *title, char *clsName, int winWidth, int winHeight, bool Fullscreen);
bool HandleMsg();
static LRESULT CALLBACK BasicWindowProc(HWND wpHWnd, UINT msg, WPARAM wParam, LPARAM lParam);
};
#endif
rendertech.cpp (the dll entry point)
----------------------------------------------------
Code:
#include "stdafx.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
and the window.cpp code:
-----------------------------------
Code:
#include "rtwindow.h"
void RTWindow::CreateWin(HINSTANCE hInstance, char *Title, char *clsName, int winWidth, int winHeight, bool Fullscreen)
{
WNDCLASSEX winClass;
winstruct.hInst=hInstance;
winstruct.gFullscreen=Fullscreen;
winstruct.iWidth=winWidth;
winstruct.iHeight=winHeight;
// Setup and register the window class
winClass.cbSize = sizeof(WNDCLASSEX);
winClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
winClass.lpfnWndProc = BasicWindowProc; // Our static function
winClass.cbClsExtra = 0;
winClass.cbWndExtra = 0;
winClass.hInstance = winstruct.hInst;
winClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winClass.lpszMenuName = NULL;
winClass.lpszClassName = clsName;
winClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&winClass))
return;
if (winstruct.gFullscreen==false)
{
// Create a normal window with a border, a caption, and an X button
winstruct.hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,
clsName,
Title,
WS_SYSMENU | WS_BORDER | WS_CAPTION | WS_VISIBLE,
100, 100,
winstruct.iWidth, winstruct.iHeight,
NULL,
NULL,
winstruct.hInst,
NULL);
}
else
{
// Create a fullscreen window, one that doesn't have anything in it
winstruct.hWnd = CreateWindowEx(NULL,
clsName,
Title,
WS_POPUP | WS_VISIBLE,
0, 0,
winstruct.iWidth, winstruct.iHeight,
NULL,
NULL,
winstruct.hInst,
NULL);
}
}
// Message loop
bool RTWindow::HandleMsg()
{
MSG msg;
while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if (msg.message == WM_QUIT)
return false;
}
return true;
}
// Our static windows message processing function
LRESULT CALLBACK RTWindow::BasicWindowProc(HWND wpHWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
default:break;
}
return DefWindowProc(wpHWnd, msg, wParam, lParam);
}
I dont find anything bad in this. Also, in the client application, i dont forget to put USERT in the preprocessor defines of the project settings. I use Visual c++7