簡體   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