右键可以转到定义,但是编译时报错,提示未声明标识符

littlemxz 2013-09-27 11:30:55
使用托管C++封装一个非托管C++写的API(为了给C#调用)。封装另一个API却可以,API的编写风格是一致的。到底是怎么回事呢
...全文
1431 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
littlemxz 2013-10-08
  • 打赏
  • 举报
回复
没有using ThostFtdcLevel2UserApi.h 的namespace
xiaohuh421 2013-09-28
  • 打赏
  • 举报
回复
#include "StdAfx.h" #pragma once 这个位置需要换一下
91program 2013-09-28
  • 打赏
  • 举报
回复
引用 6 楼 hdt 的回复:
大致看了下,应该是头文件包含问题
是的,大概是这样的。右键可跳转,说明是有定义的、但没有正确的包含。
真相重于对错 2013-09-28
  • 打赏
  • 举报
回复
大致看了下,应该是头文件包含问题
modyaj 2013-09-27
  • 打赏
  • 举报
回复
大家能猜出个啥
91program 2013-09-27
  • 打赏
  • 举报
回复
是的,上代码来分析。
真相重于对错 2013-09-27
  • 打赏
  • 举报
回复
具体代码 ??
littlemxz 2013-09-27
  • 打赏
  • 举报
回复
引用 1 楼 hdt 的回复:
具体代码 ??
引用 2 楼 91program 的回复:
是的,上代码来分析。
引用 3 楼 modyaj 的回复:
大家能猜出个啥
引用 4 楼 xiaohuh421 的回复:
能转到定义, VS经常有这个的错误. 一切都要以编译器为准, 它说没定义, 就是没定义. 我是 " Alt+G " "转到定义" 两个都用, 有时候一个失效的时候, 另一个能工作得很好.
代码按照输出那里的顺序,省略的内容用省略号表示,C开头的结构体是在API提供的头文件里边定义的,在Delegates.h遇到第一个C开头的结构体就开始报错,“错误 1 error C2144: 语法错误:“void”的前面应有“;”” Stdafx.h
#pragma once
Stdafx.cpp
#include "stdafx.h"
CTP.h
#pragma once
CTP.cpp
#include "StdAfx.h"
Util.h
 
#include "StdAfx.h"
#pragma once

#include "..\thosttraderapi\ThostFtdcLevel2UserApi.h"
#include "Struct.h"
#include "Delegates.h"


using namespace CTP;

namespace Native
{
	/// 非托管类,自动释放字符串指针内存
	class CAutoStrPtr
	{
	public:
		char* m_pChar;
		//int m_Length;
		CAutoStrPtr(String^ str);
		//CAutoStrPtr(String^ str, void* pDst, int length);
		~CAutoStrPtr();
	};


	/// 非托管类, 自动转换 Managed <==> Native 
	// M: managed
	// N: native
	template<typename M, typename N> 
	class MNConv
	{
	public:
		// 模版类的实现部分必须放在头文件里,否则链接会出错
		/// Native to Managed
		static M N2M(N* pNative){
			return safe_cast<M>(Marshal::PtrToStructure(IntPtr(pNative), M::typeid));
		};
		// Managed to Native
		static void M2N(M managed, N* pNative){
			Marshal::StructureToPtr(managed, IntPtr(pNative), true);
		};
	};

	/// 全局函数
	ThostFtdcRspInfoField^ RspInfoField(CThostFtdcRspInfoField *pRspInfo);

};
Util.cpp

#include "StdAfx.h"
#include "Util.h"

#include <string.h>
#include <memory.h>
#include <stdlib.h>

using namespace System::Runtime::InteropServices;

namespace Native
{
	CAutoStrPtr::CAutoStrPtr(String^ str)
	{
		if(str != nullptr)
		{
			m_pChar = (char*) Marshal::StringToHGlobalAnsi(str).ToPointer();
			//m_Length = strlen(m_pChar);
		}
		else
			 m_pChar = nullptr;
	}
	CAutoStrPtr::~CAutoStrPtr()
	{
		if(m_pChar != nullptr)
			Marshal::FreeHGlobal(IntPtr(m_pChar));
	}


	ThostFtdcRspInfoField^ RspInfoField(CThostFtdcRspInfoField *pRspInfo)
	{
		return safe_cast<ThostFtdcRspInfoField^>(Marshal::PtrToStructure(IntPtr(pRspInfo), ThostFtdcRspInfoField::typeid));
	}

}
Struct.h

#pragma once

using namespace System;
using namespace System::Runtime::InteropServices;

namespace CTP
{
	public enum struct EnumTeResumeType	//THOST_TE_RESUME_TYPE
	{
		THOST_TERT_RESTART = 0,
		THOST_TERT_RESUME,
		THOST_TERT_QUICK
	};
	/////////////////////////////////////////////////////////////////////////
///TFtdcInstrumentStatusType是º?一°?个?合?约?交?易°¡Á状Á¡ä态¬?类¤¨¤型¨ª
/////////////////////////////////////////////////////////////////////////
public enum struct EnumInstrumentStatusType: Byte
{
/// <summary>
///开a盘¨¬前¡ã
/// </summary>
BeforeTrading = (Byte)'0',
/// <summary>
///非¤?交?易°¡Á
/// </summary>
NoTrading = (Byte)'1',
/// <summary>
///连¢?续?交?易°¡Á
/// </summary>
Continous = (Byte)'2',
/// <summary>
///集¡¥合?竞o价?报À¡§单Ì£¤
/// </summary>
AuctionOrdering = (Byte)'3',
/// <summary>
///集¡¥合?竞o价?价?格?平?衡a
/// </summary>
AuctionBalance = (Byte)'4',
/// <summary>
///集¡¥合?竞o价?撮䨦合?
/// </summary>
AuctionMatch = (Byte)'5',
/// <summary>
///收º?盘¨¬
/// </summary>
Closed = (Byte)'6'
};
…………………………………
}
Delegates.h

#pragma once

namespace CTP
{
	// common deleagats
	public delegate void FrontConnected();
	public delegate void FrontDisconnected(int nReason);
	public delegate void HeartBeatWarning(int nTimeLapse);
	public delegate void RspUserLogin(ThostFtdcRspUserLoginField^ pRspUserLogin, ThostFtdcRspInfoField^ pRspInfo, int nRequestID, bool bIsLast);
	public delegate void RspUserLogout(ThostFtdcUserLogoutField^ pUserLogout, ThostFtdcRspInfoField^ pRspInfo, int nRequestID, bool bIsLast);
	public delegate void RspError(ThostFtdcRspInfoField^ pRspInfo, int nRequestID, bool bIsLast);

	// marketdata 
	public delegate void RspSubLevel2MarketData(ThostFtdcSpecificSecurityField^ pSpecificSecurity, ThostFtdcRspInfoField^ pRspInfo, int nRequestID, bool bIsLast);
	public delegate void RspUnSubLevel2MarketData(ThostFtdcSpecificSecurityField^ pSpecificSecurity, ThostFtdcRspInfoField^ pRspInfo, int nRequestID, bool bIsLast);
	public delegate void RspSubNGTSIndex(ThostFtdcSpecificSecurityField^ pSpecificSecurity, ThostFtdcRspInfoField^ pRspInfo, int nRequestID, bool bIsLast);
	public delegate void RspUnSubNGTSIndex(ThostFtdcSpecificSecurityField^ pSpecificSecurity, ThostFtdcRspInfoField^ pRspInfo, int nRequestID, bool bIsLast);
	public delegate void RtnLevel2MarketData(ThostFtdcLevel2MarketDataField^ pLevel2MarketData);
	public delegate void RtnNGTSIndex(ThostFtdcNGTSIndexField^ pNGTSIndex);
};

#ifdef __CTP_MA__

namespace Native
{
	delegate void Internal_FrontConnected();
	delegate void Internal_FrontDisconnected(int nReason);
	delegate void Internal_HeartBeatWarning(int nTimeLapse);
	delegate void Internal_RspError(CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	delegate void Internal_RspUserLogin(CThostFtdcRspUserLoginField *pRspUserLogin, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	delegate void Internal_RspUserLogout(CThostFtdcUserLogoutField *pUserLogout, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	

	delegate void Internal_RspSubLevel2MarketData(CThostFtdcSpecificSecurityField *pSpecificSecurity, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	delegate void Internal_RspUnSubLevel2MarketData(CThostFtdcSpecificSecurityField *pSpecificSecurity, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	delegate void Internal_RspSubNGTSIndex(CThostFtdcSpecificSecurityField *pSpecificSecurity, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	delegate void Internal_RspUnSubNGTSIndex(CThostFtdcSpecificSecurityField *pSpecificSecurity, CThostFtdcRspInfoField *pRspInfo, int nRequestID, bool bIsLast);
	delegate void Internal_RtnLevel2MarketData(CThostFtdcLevel2MarketDataField *pLevel2MarketData);
	delegate void Internal_RtnNGTSIndex(CThostFtdcNGTSIndexField *pNGTSIndex);

};

#endif
xiaohuh421 2013-09-27
  • 打赏
  • 举报
回复
能转到定义, VS经常有这个的错误. 一切都要以编译器为准, 它说没定义, 就是没定义. 我是 " Alt+G " "转到定义" 两个都用, 有时候一个失效的时候, 另一个能工作得很好.

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧