I'm using VC++ 2008
I've spent my day trying to learn about dll's and how to use them but there's a surprising lack of resources available on the internet.
I've been following a tutorial and it's given this code.
within my dll project i have a file called dllmain.cpp that says this:
I have another .cpp file with the same name as my project in which I copied this from the tutorial:Code:// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
jkgh.h contains:Code:#include "jkhg.h"
// This is an example of an exported function.
int MyDLLFunc2(char *TEXT)
{
MessageBox(NULL,TEXT,"",MB_OK);
return true;
}
And I added a .def file that contains:Code:int MyDLLFunc2(void);
Code:LIBRARY JKHG
DESCRIPTION This is my DLL file!
EXPORTS
MyDLLFunc2 @1
The application that calls the dll contains this precompiled header:
and the main cpp file contains this:Code:#pragma once
#include <windows.h>
I know this is a long post but I don't know which code is critical and which isn't.Code:#include "stdafx.h"
typedef UINT (CALLBACK* importFunc1)(char *TEXT);
HINSTANCE hDLL;
importFunc1 MyFunc2;
UINT uReturnVal;
using namespace System;
int main(array<System::String ^> ^args)
{
hDLL = LoadLibrary("c:\\jkhg.dll");
if (hDLL != NULL)
{
MyFunc2 = (importFunc1)GetProcAddress(hDLL,"MyDLLFunc2");
if (!MyFunc2)
{
//Show error message
FreeLibrary(hDLL);
return false;
}
else
{
uReturnVal = MyFunc2("HELLO WORLD!");
}
}
return true;
}
And now to my problem. I successfully load the dll from c:\jkhg.dll but now matter what I do myFunc2 always remains empty and this block of code in viI.cpp always executes:
I'm gratefull for any amount of help or light-shedding.Code:if (!MyFunc2)
{
//Show error message
FreeLibrary(hDLL);
return false;
}
sorry about the lousy names, I tend to bang on the keyboard during tutorial readings.