error LNK2001: unresolved external symbol

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2006
Posts: 1
Reputation: chavez is an unknown quantity at this point 
Solved Threads: 0
chavez chavez is offline Offline
Newbie Poster

error LNK2001: unresolved external symbol

 
0
  #1
Jan 6th, 2006
Hi guys!

I get this exact error Main.obj : error LNK2001: unresolved external symbol "public: int __thiscall CGui::GetActiveState(void)" (?GetActiveState@CGui@@QAEHXZ)
Release/test.dll : fatal error LNK1120: 1 unresolved externals

Heres the code:
  1. #include "Gui.h"
  2.  
  3. #define WINDOW "3D World"
  4.  
  5. HWND ( __stdcall *pCreateWindowExA )( DWORD, LPCTSTR, LPCTSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID );
  6. FARPROC ( __stdcall *pGetProcAddress )( HMODULE, LPCSTR );
  7. BOOL ( __stdcall *pSetCursorPos )( int, int );
  8. BOOL ( __stdcall *pGetCursorPos )( LPPOINT );
  9.  
  10. void *InterceptDllCall( char *szDllName, char *szFuncName, DWORD dwNewFunction );
  11.  
  12. WNDPROC pWndProc;
  13.  
  14. LRESULT __stdcall myWndProc( HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam )
  15. {
  16. switch( iMsg )
  17. {
  18. case WM_SYSKEYDOWN:
  19. case WM_KEYDOWN:
  20. case WM_SYSKEYUP:
  21. case WM_SYSCHAR:
  22. case WM_CHAR:
  23. case WM_KEYUP:
  24. case WM_MOUSEMOVE:
  25. case WM_LBUTTONDOWN:
  26. case WM_LBUTTONUP:
  27. case WM_RBUTTONDOWN:
  28. case WM_RBUTTONUP:
  29. // Check for these messages only.
  30. if( !Gui.HandleMsg( iMsg, wParam, lParam ) )
  31. return( 0 );
  32. }
  33.  
  34. // Call original WinProc
  35. return( CallWindowProc( pWndProc, hWnd, iMsg, wParam, lParam ) );
  36. }
  37.  
  38. void SubClass( HWND hWnd )
  39. {
  40. Gui.SetWinHandle( hWnd );
  41.  
  42. // Store the original WinProc
  43. pWndProc = ( WNDPROC )GetWindowLong( Gui.GetWinHandle( ), GWL_WNDPROC );
  44.  
  45. // Set the game's WinProc to ours.
  46. SetWindowLong( Gui.GetWinHandle( ), GWL_WNDPROC, ( long )myWndProc );
  47. }
  48.  
  49. BOOL __stdcall mySetCursorPos( int x, int y )
  50. {
  51. Gui.SetOrigMouse( x, y );
  52.  
  53. if( Gui.GetActiveState( ) == 1 )
  54. return( TRUE );
  55.  
  56. return( pSetCursorPos( x, y ) );
  57. }
  58.  
  59. BOOL __stdcall myGetCursorPos( LPPOINT lpPoint )
  60. {
  61. BOOL bRetval = pGetCursorPos( lpPoint );
  62.  
  63. if( Gui.GetActiveState( ) == 1 )
  64. {
  65. // So the view doesnt move.
  66. lpPoint->x = Gui.GetOrigMouse( 0 );
  67. lpPoint->y = Gui.GetOrigMouse( 1 );
  68. return( TRUE );
  69. }
  70.  
  71. return( bRetval );
  72. }
  73.  
  74. HWND __stdcall myCreateWindowExA( DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam )
  75. {
  76. HWND hRetval = pCreateWindowExA( dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam );
  77.  
  78. if( lpWindowName && strstr( lpWindowName, WINDOW ) )
  79. SubClass( hRetval );
  80.  
  81. return( hRetval );
  82. }
  83.  
  84. FARPROC __stdcall myGetProcAddress( HMODULE hModule, LPCSTR lpProcName )
  85. {
  86. if( HIWORD( lpProcName ) )
  87. {
  88. if( !strcmp( lpProcName, "GetProcAddress" ) )
  89. {
  90. return( ( FARPROC )myGetProcAddress );
  91. }
  92. else if ( !strcmp( lpProcName, "glEnable" ) )
  93. {
  94. // hook glEnable, store original in pglEnable
  95. pGetProcAddress( hModule, lpProcName );
  96. _asm mov [pglEnable], eax
  97.  
  98. return( ( FARPROC )myglEnable );
  99. }
  100. else if ( !strcmp( lpProcName, "glViewport" ) )
  101. {
  102. // hook glViewport, store original in pglViewport
  103. pGetProcAddress( hModule, lpProcName );
  104. _asm mov [pglViewport], eax
  105.  
  106. return( ( FARPROC )myglViewport );
  107. }
  108. }
  109.  
  110. return( pGetProcAddress( hModule, lpProcName ) );
  111. }
  112.  
  113. bool __stdcall DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved )
  114. {
  115. switch( dwReason )
  116. {
  117. case DLL_PROCESS_ATTACH:
  118. {
  119. // hook GetProcAddress, CreateWindowExA, GetCursorPos and SetCursorPos
  120.  
  121. InterceptDllCall( "kernel32.dll", "GetProcAddress", ( DWORD )&myGetProcAddress );
  122. _asm mov [pGetProcAddress], eax
  123.  
  124. InterceptDllCall( "user32.dll", "CreateWindowExA", ( DWORD )&myCreateWindowExA );
  125. _asm mov [pCreateWindowExA], eax
  126.  
  127. InterceptDllCall( "user32.dll", "GetCursorPos", ( DWORD )&myGetCursorPos );
  128. _asm mov [pGetCursorPos], eax
  129.  
  130. InterceptDllCall( "user32.dll", "SetCursorPos", ( DWORD )&mySetCursorPos );
  131. _asm mov [pSetCursorPos], eax
  132. break;
  133. }
  134. }
  135.  
  136. return( true );
  137. }
  138.  
  139. #define MakePtr( type, ptr, addValue )( type )( ( DWORD )( ptr ) + ( DWORD )( addValue ) )
  140.  
  141. void *InterceptDllCall( char *szDllName, char *szFunctionName, DWORD pNewFunction )
  142. {
  143. HMODULE hModule = GetModuleHandle( 0 );
  144.  
  145. PIMAGE_DOS_HEADER pDosHeader;
  146. PIMAGE_NT_HEADERS pNTHeader;
  147. PIMAGE_IMPORT_DESCRIPTOR pImportDesc;
  148. PIMAGE_THUNK_DATA pThunk;
  149.  
  150. DWORD dwOldProtect, dwOldProtect2;
  151.  
  152. void *pOldFunction;
  153.  
  154. if( !( pOldFunction = GetProcAddress( GetModuleHandle( szDllName ), szFunctionName ) ) )
  155. return( NULL );
  156.  
  157. pDosHeader = ( PIMAGE_DOS_HEADER )hModule;
  158.  
  159. if( pDosHeader->e_magic != IMAGE_DOS_SIGNATURE )
  160. return( NULL );
  161.  
  162. pNTHeader = MakePtr( PIMAGE_NT_HEADERS, pDosHeader,pDosHeader->e_lfanew );
  163.  
  164. if( pNTHeader->Signature != IMAGE_NT_SIGNATURE || ( pImportDesc = MakePtr( PIMAGE_IMPORT_DESCRIPTOR, pDosHeader, pNTHeader->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_IMPORT ].VirtualAddress ) ) == ( PIMAGE_IMPORT_DESCRIPTOR )pNTHeader )
  165. return( NULL );
  166.  
  167. while( pImportDesc->Name )
  168. {
  169. char *szModuleName = MakePtr( char *, pDosHeader, pImportDesc->Name );
  170. if( !stricmp( szModuleName, szDllName ) )
  171. break;
  172. pImportDesc++;
  173. }
  174. if( pImportDesc->Name == NULL )
  175. return( NULL );
  176.  
  177. pThunk = MakePtr( PIMAGE_THUNK_DATA, pDosHeader, pImportDesc->FirstThunk );
  178. while( pThunk->u1.Function )
  179. {
  180. if( pThunk->u1.Function == ( DWORD * )pOldFunction )
  181. {
  182. VirtualProtect( ( void * )&pThunk->u1.Function, sizeof( DWORD ), PAGE_EXECUTE_READWRITE, &dwOldProtect );
  183. pThunk->u1.Function = ( DWORD * )pNewFunction;
  184. VirtualProtect( ( void * )&pThunk->u1.Function, sizeof( DWORD ), dwOldProtect, &dwOldProtect2 );
  185. return( pOldFunction );
  186. }
  187. pThunk++;
  188. }
  189. return( NULL );
  190. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: error LNK2001: unresolved external symbol

 
0
  #2
Jan 6th, 2006
you have to either include the implementation file for Gui class in the dll project, or link with a *.lib file that includes it in either another dll or static library.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC