Alright guys this is an extension on my last post which was solved and that part is working great (link below)
Not finding function using GetProcAddress() C++ VBexpress 13
unfortunately another area of misunderstanding came about. below is the code i'm about to reference:
#include "stdafx.h"
#include <iostream>
#include "Windows.h"
#include <stdio.h>
typedef int(__cdecl *MYPROC)(LPWSTR);
using namespace std;
int main()
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
hinstLib = LoadLibrary(TEXT("testDLL.dll"));
if (hinstLib != NULL)
{
ProcAdd = (MYPROC)GetProcAddress(hinstLib, "?Add@MyMathFuncs@MathFuncs@@SANNN@Z");
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
c=(ProcAdd)(L"something here");
}
fFreeResult = FreeLibrary(hinstLib);
}
return 0;
}
The issue: having trouble interfacing with the functions. the program recognizes the DLL and the function. I'm sure it has something to do with the typedef, the assignment to ProcAdd, and my actual call of the function. In this example i'm calling a function that adds doubles together. Obviously i need to pass 2 doubles. it seems like logic would dictate i could replace the typedef with 'typedef int(__cdecl *MYPROC)(double,double);' or something similar and replace the L"something here" with 2 doubles and assign it to a value. The are no runtime errors when i do this but i just gives a large negative number for the returned number. What exactly are happening in these 2 lines that are throwing me? i'm not even sure what to specifically unfortunately. i understand what _cdecl is.
Short background: i'm having to interface with a DLL that i dont have a .lib file for. I was having trouble so i made a DLL with the MS tutorial at http://msdn.microsoft.com/en-us/library/ms235636.aspx and am referencing that DLL with the code above, which was taken from another MS tutorial if i remember correctly.
Any help in understanding these basic concepts would be greatly appreciated. thank you!