【发布时间】:2014-01-21 12:29:21
【问题描述】:
我正在处理从一些旧的 Delphi 代码到 VC++ 2013 的移植,我遇到了一个错误,我觉得应该很容易解决,但我一生都无法弄清楚......
问题是这样的:我在本地文件 Utils.h 中有许多常用实用程序函数,我将其部署为 Windows 窗体的一部分。此标头中的大多数 (90%) 函数都可以正常工作。但是,GetMsg(...) 会引发 C3861 Identifier not found 错误...
Utils.h (sn-p): GetMsg 在底部声明
#pragma once
/*------------------------------------------------------------------------*
Includes:
*------------------------------------------------------------------------*/
using namespace std;
/*------------------------------------------------------------------------*
Constants:
*------------------------------------------------------------------------*/
#define GET_MSG_TIMEOUT 2
/*------------------------------------------------------------------------*
Typedefs, Structs, Enums:
*------------------------------------------------------------------------*/
typedef union
{
unsigned long ui32;
unsigned char ui8[4];
} UI32_UI8;
typedef union
{
unsigned short ui16;
unsigned char ui8[2];
} UI16_UI8;
typedef union
{
float f;
unsigned char ui8[4];
} F_UI8;
typedef struct
{
string sName;
string sVersion;
string sCompany;
string sCopyright;
} PRODUCT_INFORMATION;
/*------------------------------------------------------------------------*
Prototypes:
*------------------------------------------------------------------------*/
unsigned short SwapShort(unsigned short aShort);
float SwapFloat(float aFloat);
unsigned long SwapLong(unsigned long aLong);
unsigned int ReadLine(unsigned char *msgBuf, SerialPort^ Hdl, bool ReturnLF);
void __stdcall FillTheBuffer(char *buf, String sss, int length);
string __stdcall FillTheString(string sss, int length);
unsigned int __stdcall GetMsg(SerialPort^ Hdl, unsigned char *msgBuf);
Utils.cpp 中的 GetMsg 定义:
//---------------------------------------------------------
unsigned int __stdcall GetMsg(SerialPort^ Hdl, unsigned char *msgBuf)
{
...
}
最后,GetMsg 在表单文件中的用法:
#include "Utils.h"
...
void MainForm::UploadButton_Click
(System::Object^ object, System::EventArgs^ e)
{
...
SwapShort(1); //Works fine, also declared in Utils.h
GetMsg(spCom, inBuf); //C3861 ERROR
...
}
其中 spCom 是在 windows 窗体中包含、配置和打开的 (SerialPort^)。 inBuf 是一个简单的字符数组 (char*),用于缓冲输入。我尝试重命名函数,认为其他文件中可能存在无意的冲突/过载,但无济于事。
有什么建议吗?谢谢,提前
【问题讨论】:
-
@KenWhite 在 C++/CLI 中它是一个托管引用
-
我缺少 SerialPort 的声明
-
@Vinzenz:谢谢。我没有在 C++/CLI 中做任何事情,所以我不知道这种用途。
-
您应该将您的解决方案作为实际答案发布,这样问题就不会显得没有答案。
标签: winapi visual-c++ c++-cli