如何修复这些仅在 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/en-us/library/zxk0tw93.aspx
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 使用 TDM-GCC 4.9.2 的 DevC++ IDE 中的额外限定错误
- 运行时出现C++ (DevC++) 分段错误
- 我正在尝试用 DevC++ 编译一个套接字程序,但每次我这样做时,我都会收到很多链接器错误,如下所示:
- DevC++ 编译器错误
- 如何修复这些仅在 Visual C++ 中发生而不在 DevC++ 中发生的错误
- 在DevC++中使用boost:编译器集验证错误
- DevC++上出现了一个奇怪的sizeof()错误
- Wininet 给出链接器错误我正在使用 devc++
- ISO c++禁止在devc++中比较指针和整数[-fpermissive]错误