繁体   English   中英

如何解决仅在Visual C ++中而不在DevC ++中发生的这些错误?

[英]How can I fix these errors that only happens in Visual C++ but not in DevC++?

#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");

   }
}

当我使用DevC ++进行编译时,代码可以正常工作,但是当我尝试在Visual C ++中进行编译时,会出现很多错误,我该如何解决?

输出中显示以下错误:

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

在MSVC下,调用约定应放在括号内

typedef short (__stdcall *PtrInp)(short EndPorta);
typedef void (__stdcall *PtrOut)(short EndPorta, short datum);

另请确保在项目设置中使用MBCS (多字节字符集)

它必须是__stdcall ,即双下划线。 除此之外,应将分类器__stdcall应用于函数本身,而不是返回值:

typedef short (__stdcall *PtrInp)(short EndPorta);
typedef void (__stdcall *PtrOut)(short EndPorta, short datum);

在此处查看更多示例: http : //msdn.microsoft.com/zh-cn/library/zxk0tw93.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM