GetProcAddress() returns a pointer. Call to the pointer fails outside IDE

  • Thread starter Thread starter FerroCoder
  • Start date Start date
F

FerroCoder

Guest
This one has me and the partner organization bamboozled. Below a small code segment. The names have been changes to protect the innocent:

typedef bool( *MABFUNTKPTR )(); // bool return, empty parameter list

bool CMainApp::initialize_partner( void )
{

HINSTANCE l_hiPartnerSDKDLL;
l_hiPartnerSDKDLL = ::AfxLoadLibrary( "C:\\Program Files (x86)\\MyCompany\\Partner.dll" );

AfxMessageBox( "MA: Test Point 1" );

if( l_hiPartnerSDKDLL != NULL )
{

AfxMessageBox( "MA: Test Point 2" );

MABFUNTKPTR pSDKInitializeFunction = NULL;

pSDKInitializeFunction =
( MUIBFUNTKPTR )::GetProcAddress( lp_hil_hiPartnerSDKDLL SDKDLL,
"PartnerInitialiseSDK" );

if( pSDKInitializeFunction != NULL )
{

AfxMessageBox( "MA: Test Point 3" );
pSDKInitializeFunction();
AfxMessageBox( "MA: Test Point 4" );

} // if( pSDKInitializeFunction != NULL )

} // if( l_hiPartnerSDKDLL != NULL )

} // initialize_partner()

This code executes properly in the IDE in both debug and release builds, using both debug and release builds of PartnerSDK.dll. However, outside the IDE the program fails on the call to pSDKInitializeFunction(). In the IDE "MA: Test Point 3" and "MA: Test Point 4" appear without error. Outside the IDE "MA: Test Point 3" appears, but the program crashes without displaying "MA: Test Point 4"

Using the debug PartnerSDK.dll the crash generates this error. (Cannot seem to include images):

Microsoft Visual C++ Runtime Library

Debug Assertion Failed:

Program: C:\Program Files (x86)\MyCompany\MainApp.exe

File: minkernel\crts\ucrt\src\appcrf\stdio\output.cpp

Line: 32

Expression: stream != nullptr

....

If running the release build of PartnerSDK.dll, the program just crashes without visible indication.

This behavior leads me to believe that there is a pointer failure in the Partner.DLL except that:

  • The call does not fail inside the IDE.
  • A small console app produced by the partner makes the PartnerInitialiseSDK() call up front, outside the IDE, without error.

Can anyone offer any advice?

Thanks in advance.

FC

This code executes properly in the IDE in both debug and release
This code executes properly in the IDE in both debug and release

Continue reading...
 
Back
Top