Hello everyone,
I am attempting to make a function call from a dll file, the function in question is suppose to load a separate window. However when I make the call I the windows is loaded(I can see the GUI), but crashes straight away.
I therefore attempted to write a small sample app with a function of same return type and number of parameters as the one I am suppose to be calling, just for testing purposes, however I am running into a memory access violation error while trying to implement the sample app to execute a function from a dll; leading me to conclude that there is a fundamental mistake in my code.
I have to source files,
File 1: LibTest.cpp which is as follow
Code:
// LibTest.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include <Windows.h>
void DisplayMsg(){
MessageBox(0, L"Hello from test lib", L"Test Lib", MB_OK);
}
With file one I was able to create a dll, please note that I must use dynamic loading since the ".lib" file is not available for my final task. Once the dll created, I created a second sample app to attempt to call the function above, here is the code of the procedure making the call:
Code:
#include <windows.h>
void LoadMfKbdDll() {
//Loading the library
HINSTANCE hDLL = LoadLibrary(TEXT("LibTest.dll"));
if (hDLL != NULL){
MessageBox(0, L"Test Lib Loaded", L"Test Lib", MB_OK);
//Get The point to the Display Message function in the dll
typedef void (__stdcall* pICFUNC)(); //building a template for the DisplayMsg function
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE(hDLL),"DisplayMsg");
pICFUNC DisplayMsg;
DisplayMsg = pICFUNC(lpfnGetProcessID);
DisplayMsg(); //calling the function
FreeLibrary(hDLL); //releasing the dll
}
else {
MessageBox(0, L"Error Loading libTest.dll", L"Login UI", MB_OK);
}
}
Now my problem is every time I attempt to run the file, I run into a memory access violation, I tried to debug as much as I could but I have now hit a solid wall, any help or suggestions would be greatly appreciated. Thanks
Yan
Note:
1) I am using VS 2010, SP1 on a Win7 x64 SP1 machine.
2) I have posted this question in another forum also, I hope it is not against regulations.