#include <stdio.h>
#include <conio.h>
#include <windows.h>
typedef short _stdcall (*PtrInp)(short EndPorta);
typedef void _stdcall (*PtrOut)(short EndPorta, short datum);
HINSTANCE hLib;
PtrInp inportB;
PtrOut outportB;
int main()
{
/*Inpout32*/
//Carrega a DLL na memória.
hLib = LoadLibrary("inpout32.dll");
if(hLib == NULL)
{
printf("Error.");
getch();
}
else {
inportB = (PtrInp) GetProcAddress(hLib, "Inp32");
if(inportB == NULL)
{
printf("\nError2");
}
//Obtém o endereço da função Out32 contida na DLL.
outportB = (PtrOut) GetProcAddress(hLib, "Out32");
if(outportB == NULL)
{
printf("Error3");
}
}
When I compile using DevC++, the code works just fine, but when I try to compile it in Visual C++ it gives a bunch of errors, how can I fix them?
The following errors is shown in the output:
1><PATH>(12) : error C2059: syntax error : '('
1><PATH>(13) : error C2059: syntax error : '('
1><PATH>(15) : error C2065: 'PtrInp' : undeclared identifier
1><PATH>(15) : error C2146: syntax error : missing ';' before identifier 'inportB'
1><PATH>(15) : error C2065: 'inportB' : undeclared identifier
1><PATH>(16) : error C2065: 'PtrOut' : undeclared identifier
1><PATH>(16) : error C2146: syntax error : missing ';' before identifier 'outportB'
1><PATH>(16) : error C2065: 'outportB' : undeclared identifier
1><PATH>(30) : error C2065: 'inportB' : undeclared identifier
1><PATH>(30) : error C2065: 'PtrInp' : undeclared identifier
1><PATH>(30) : error C2146: syntax error : missing ';' before identifier 'GetProcAddress'
1><PATH>(31) : error C2065: 'inportB' : undeclared identifier
1><PATH>(36) : error C2065: 'outportB' : undeclared identifier
1><PATH>(36) : error C2065: 'PtrOut' : undeclared identifier
1><PATH>(36) : error C2146: syntax error : missing ';' before identifier 'GetProcAddress'
1><PATH>(37) : error C2065: 'outportB' : undeclared identifier
1><PATH>(53) : error C3861: 'outportB': identifier not found
1><PATH>(56) : error C3861: 'outportB': identifier not found
1><PATH>(59) : error C3861: 'outportB': identifier not found
1><PATH>(62) : error C3861: 'outportB': identifier not found
1><PATH>(65) : error C3861: 'outportB': identifier not found
1><PATH>(68) : error C3861: 'outportB': identifier not found
1><PATH>(71) : error C3861: 'outportB': identifier not found
1><PATH>(74) : error C3861: 'outportB': identifier not found
1><PATH>(80) : error C3861: 'outportB': identifier not found
Under MSVC the calling convention should be placed within the parenthesis
typedef short (__stdcall *PtrInp)(short EndPorta);
typedef void (__stdcall *PtrOut)(short EndPorta, short datum);
Please also make sure you use MBCS (Mutli Byte Charecter Set) within your project settings
It has to be __stdcall
, ie a double-underscore. In addition to this, the classifier __stdcall
should be applied to the function itself, not to the return value:
typedef short (__stdcall *PtrInp)(short EndPorta);
typedef void (__stdcall *PtrOut)(short EndPorta, short datum);
See more examples here: http://msdn.microsoft.com/en-us/library/zxk0tw93.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.