Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compiles, but Freezes up

Status
Not open for further replies.

jamez05

Programmer
Jul 29, 2005
130
US
I'm using Visual Studio 2005

I have a function named "CallBIOWDLL" that calls a third party dll. When I compile and run the program at this point, it works fine. However, When I call CallBIOWDLL from my main function, it compiles, but when I run the program it freezes. I'm working with a simple win32 console program. Below is the code and debugging information. I've been struggling with this for a long time so any help is greatly appreciated:

Code:
// test5.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>

#define MAXLEN 360

char Details[12000];
char ErrMess[1200];
char numLines[12];


char EstLin[15];
char EstNon[15];
char EstUlt[15];
char EstPrim[15];
char EstMitiLin[15];
char EstMitiNon[15];
char UltTime[30];
char PrimTime[30];

char szString[MAXLEN] ;

int CallBIOWDLL(void)
{ 
    
	strcpy(szString,"O=C");
	/* get handle to dll */
     HINSTANCE hGetProcIDDLL = LoadLibrary("C:\\WINDOWS\\system32\\BIOWDLL.dll");

     /* get pointer to the function in the dll*/
     FARPROC lpfnGetProcessID = GetProcAddress(HMODULE(hGetProcIDDLL), "GetSrcBIOWIN");

     /* Define the Function in the DLL for reuse. This is just prototyping
        the dll's function. A mock of it. Use "stdcall" for maximum compatibility.
 */   
     typedef int (__stdcall * pICFUNC)(char*,char*,char*);

     pICFUNC MyFunction;
     MyFunction = pICFUNC(lpfnGetProcessID);


	 /* The actual call to the function contained in the dll */ 
     int intMyReturnVal = MyFunction(szString,"test2",EstLin);

     /* Release the Dll */
     FreeLibrary(hGetProcIDDLL);

     /* The return val from the dll */
     return intMyReturnVal;
}


int _tmain(int argc, _TCHAR* argv[])
{
	CallBIOWDLL();
	return 0;
}

Debugging info:
Code:
'test5.exe': Loaded 'C:\Documents and Settings\epajn\My Documents\Visual Studio 2005\Projects\test5\Debug\test5.exe', Symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcr80d.dll', Symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\system32\BIOWDLL.dll', Binary was not built with debug information.
'test5.exe': Loaded 'C:\WINDOWS\system32\version.dll', No symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', No symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll', No symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\system32\imm32.dll', No symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\system32\lpk.dll', No symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\system32\usp10.dll', No symbols loaded.
'test5.exe': Loaded 'C:\WINDOWS\system32\apphelp.dll', No symbols loaded.
The thread 'Win32 Thread' (0xd24) has exited with code 0 (0x0).
Unhandled exception at 0x00000000 in test5.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x00000000 in test5.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x00000000 in test5.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x00000000 in test5.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x00000000 in test5.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x00000000 in test5.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x00000000 in test5.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x00000000 in test5.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x00000000 in test5.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x00000000 in test5.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x00000000 in test5.exe: 0xC0000005: Access violation reading location 0x00000000.
The program '[3852] test5.exe: Native' has exited with code 0 (0x0).
 
> HINSTANCE hGetProcIDDLL = LoadLibrary("C:\\WINDOWS\\system32\\BIOWDLL.dll");
> FARPROC lpfnGetProcessID = GetProcAddress(HMODULE(hGetProcIDDLL), "GetSrcBIOWIN");
You could at least check for success, before you go off potentially using NULL as a function pointer.


--
 
What do you mean by check for success? I need to take a class or read a good book. However, I did figure out how to call the dll implicitly in a windows program I've written in C. When I convert it to C++ though, it errors out. It has something to do with the character type. Do you have any advice? Below is the code:
Code:
#include <windows.h>

__declspec ( dllexport )int WINAPI GetSrcBIOWIN (PSTR cSmilePass,
   PSTR cChemical, PSTR EstLin, PSTR EstNon, PSTR EstUlt, PSTR EstPrim,
   PSTR UltTime, PSTR PrimTime, PSTR EstMitiLin, PSTR EstMitiNon,
   PSTR DetailResults, PSTR numLines, PSTR ErrorMess);


#define MAXLEN 360

char Details[12000];
char ErrMess[1200];
char numLines[12];

char EstLin[15];
char EstNon[15];
char EstUlt[15];
char EstPrim[15];
char EstMitiLin[15];
char EstMitiNon[15];
char UltTime[30];
char PrimTime[30];



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    PSTR szCmdLine, int nCmdShow)
{
   char szBuffer[MAXLEN] ;

	int Ret1 = GetSrcBIOWIN("O=C","ChemName",
               EstLin,EstNon,EstUlt,EstPrim,
               UltTime,PrimTime,EstMitiLin,EstMitiNon,
               Details,numLines,ErrMess);	

    sprintf(szBuffer,"Linear: %s  NonLinear: %s  Ult: %s  Prim: %s  Miti: %s  NonMiti: %s",
          EstLin,EstNon,EstUlt,EstPrim,EstMitiLin,EstMitiNon);

	
	MessageBox(NULL, szBuffer, "Note", MB_OK);
    return 0;
}
 
Figured it out.

Added extern "C" in front of _declspec
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top