GetProcAddress is returning null...
I am using the latest C++ Builder from CodeGear.
There is an API.h and file1.cpp - then I show my output... no compiling problems - just keep getting null!
-------------------file1.cpp---------------------
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma argsused
#pragma package(smart_init)
#include "api.h"
#include <vcl.h>
#include <iostream>
/*
* The handle for the cdbdapi Libray
*/
HMODULE hm = NULL;
/*
* Holders for DLL Imported functions
*/
TInitAPI InitAPI;
TCloseAPI CloseAPI;
TGetMeet GetMeet;
TGetTime GetTime;
TGetRace GetRace;
TResult Result;
TGetID GetID;
TLoadShadow LoadShadow;
TEngineFromSysTray EngineFromSysTray;
TEngineToSysTray EngineToSysTray;
TGetQuinella GetQuinella;
TGetExacta GetExacta;
TGetTrifecta GetTrifecta;
using namespace std;
void exit_application ( void );
//---------------------------------------------------------------------------
void exit_application ( void )
{
int t;
cin >> t;
exit (0);
}
int main(int argc, char* argv[])
{
//try to load the library, return to console if not found
if( ( hm = LoadLibrary( "C:\\Users\\Yiannis\\Desktop\\HR2\\cdbdapi.dll" ) ) == NULL )
{
cout << "LoadLibrary: DLL Could Not Be Loaded." << endl;
exit_application ();
}
else
{
cout << "LoadLibrary: DLL Loaded Fine." << endl;
}
/*
* Get the addresses for the functions being used.
*/
if((InitAPI=(TInitAPI)GetProcAddress(hm,"InitAPI"))==NULL)
cout << "InitAPI(): Address Not Found!" << endl;
if((CloseAPI=(TCloseAPI)GetProcAddress(hm,"CloseAPI"))==NULL)
cout << "CloseAPI(): Address Not Found!" << endl;
if((GetMeet=(TGetMeet)GetProcAddress(hm,"GetMeet"))==NULL)
cout << "GetMeet(): Address Not Found!" << endl;
//if((GetTime=(TGetTime)GetProcAddress(hm,"GetTime"))==NULL)
// cout << "GetTime(): Address Not Found!" << endl;
if((GetRace=(TGetRace)GetProcAddress(hm,"GetRace"))==NULL)
cout << "GetRace(): Address Not Found!" << endl;
if((Result=(TResult)GetProcAddress(hm,"Result"))==NULL)
cout << "Result(): Address Not Found!" << endl;
if((GetID=(TGetID)GetProcAddress(hm,"GetID"))==NULL)
cout << "GetID(): Address Not Found!" << endl;
if((LoadShadow=(TLoadShadow)GetProcAddress(hm,"LoadShadow"))==NULL)
cout << "LoadShadow(): Address Not Found!" << endl;
if((EngineFromSysTray=(TEngineFromSysTray)GetProcAddress(hm,"EngineFromSysTray"))==NULL)
cout << "EngineFromSysTray(): Address Not Found!" << endl;
if((EngineToSysTray=(TEngineToSysTray)GetProcAddress(hm,"EngineToSysTray"))==NULL)
cout << "EngineToSysTray(): Address Not Found!" << endl;
if((GetQuinella=(TGetQuinella)GetProcAddress(hm,"GetQuinella"))==NULL)
cout << "GetQuinella(): Address Not Found!" << endl;
if((GetExacta=(TGetExacta)GetProcAddress(hm,"GetExacta"))==NULL)
cout << "GetExacta(): Address Not Found!" << endl;
if((GetTrifecta=(TGetTrifecta)GetProcAddress(hm,"GetTrifecta"))==NULL)
cout << "GetTrifecta(): Address Not Found!" << endl;
if ( !FreeLibrary ( hm ) ) {
cout << "FreeLibrary(): Could not unload DLL" << endl;
}
exit_application ();
return 1;
}
//---------------------------------------------------------------------------
-----------api.h--------
//A few defines not show...
typedef int _stdcall (*TInitAPI)( void );
typedef void _stdcall (*TCloseAPI)( void );
typedef int _stdcall (*TGetMeet)(char *, int *); //buf, len
typedef int _stdcall (*TGetTime)(char *, int *); //buf, len
typedef int _stdcall (*TGetRace)(char *, int *, int, char *, char *, int, int, int, int); //buf, len, refstate, meet, race, state, pool, updates, summary
typedef int _stdcall (*TGetQuinella)(char *, int *, int, char *, char *, int); //buf, len, refstate, meet, race, state
typedef int _stdcall (*TGetExacta)(char *, int *, int, char *, char *, int); //buf, len, refstate, meet, race, state
typedef int _stdcall (*TGetTrifecta)(char *, int *, int, char *, char *, int); //buf, len, refstate, meet, race, state
typedef int _stdcall (*TResult)(char *, int *, int, char *, char *, int); //buf, len, refstate, meet, race, state
typedef int _stdcall (*TGetID)(char *, int *); //buf, len
typedef int _stdcall (*TLoadShadow)(char *); //filename
typedef int _stdcall (*TEngineToSysTray)( void );
typedef int _stdcall (*TEngineFromSysTray)( void );
------end api.h-----------
My output!
LoadLibrary: DLL Loaded Fine.
InitAPI(): Address Not Found!
CloseAPI(): Address Not Found!
GetMeet(): Address Not Found!
GetRace(): Address Not Found!
Result(): Address Not Found!
GetID(): Address Not Found!
LoadShadow(): Address Not Found!
EngineFromSysTray(): Address Not Found!
EngineToSysTray(): Address Not Found!
GetQuinella(): Address Not Found!
GetExacta(): Address Not Found!
GetTrifecta(): Address Not Found!
by: AlexFMPosted on 2007-06-21 at 22:49:48ID: 19339210
Using dumpbin or Dependency Walker check actual function names exported from cdbdapi.dll. If this is C++ Dll, function names can be decorated, this prevents them to be called by this way.