无法调用 SCALE 文件夹中的 DLL“sdm00.dll”。我正在尝试调用“SpC”函数,该函数将参数作为“数字”转换为 asci 码+“SpApp|”。但不能加载 DLL &调用函数.PLZ帮助
#include <windows.h>
#include <stdio.h>
#include <iostream>
using namespace std;
typedef string (__cdecl *MYPROC)(string);
char asc(int a)
{
char var;
var = (char)a;
return var;
}
int main()
{
char z;
z = asc(20);
string str1;
string str2;
string str3;
string retval;
str1 = z;
str2 = "SpApp|";
str3 = str1 + str2;
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
// Get a handle to the DLL module
hinstLib = LoadLibrary(TEXT("c:\\SCALE\\sdm00.dll"));
//If the handle is valid, try to get the function address
if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "SpC");
// If the function address is valid, call the function.
if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
cout << "Function is called" << endl;
string MyRetValue;
MyRetValue = (string)(ProcAdd)(str3);
cout << MyRetValue << endl;
}
else
{
cout << "Function cannot be called" << endl;
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
}
// If unable to call the DLL function, use an alternative.
if (!fRunTimeLinkSuccess)
printf("Message printed from executable\n");
std::cin.get();
return 0;
}