DLL problem

This is a discussion on DLL problem within the C++ Programming forums, part of the General Programming Boards category; Im making a dll in visual c++7. I have an exported class, which looks like this: class RTDLL RTWindow { ...

  1. #1
    Unregistered
    Guest

    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!!

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Try prefixing the function with the __declspec() instaead of the whole class

  3. #3
    Unregistered
    Guest
    You mean try to export just a function, right? Ive tried it. Didnt work, the same error.

  4. #4
    Unregistered
    Guest
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DLL Function / Load Library Problem
    By cboard_member in forum Windows Programming
    Replies: 5
    Last Post: 12-10-2005, 09:11 AM
  2. Replies: 1
    Last Post: 09-18-2005, 09:06 PM
  3. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 04:29 AM
  4. std::string vs char* DLL problem
    By aker_y3k in forum C++ Programming
    Replies: 13
    Last Post: 10-02-2002, 09:05 AM
  5. VCL and DLL class problem
    By borland_man in forum C++ Programming
    Replies: 1
    Last Post: 02-13-2002, 10:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21