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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

So Close..

Status
Not open for further replies.

jamez05

Programmer
Joined
Jul 29, 2005
Messages
130
Location
US
I have an executable that needs to call an external DLL. This DLL accepts a string and opens up a new window.

If I call it in VB, the window opens fine. I get the CPP program to call it, but the window closes right away.
I'm missing something, but not sure what. Below is the code:
Code:
*/
main()
{
    
     /* get handle to dll */
     HINSTANCE hGetProcIDDLL = LoadLibrary("C:\\WINDOWS\\system32\\Chem2D.dll");

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

     /* 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*);

     pICFUNC MyFunction;
     MyFunction = pICFUNC(lpfnGetProcessID);


	 /* The actual call to the function contained in the dll */ 
     int intMyReturnVal = MyFunction("CCCCC");

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

     /* The return val from the dll */
	
	 return intMyReturnVal;
	 
	 cin.get();
}
 
If your intention was for the cin.get(); to wait until you press enter before closing the cmd window you'll need to move it before you return from main().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top