本文介绍了通用C ++库unsing Visual Studio 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在开发一个具有客户端和服务器的临时应用程序。客户端使用C#编写为带有表单等的普通Windows应用程序。服务器将接收TCP / IP套接字消息以进行处理和响应。



我希望SERVER成为一个C ++公共代码,可以链接到Windows和Linux,只需更少的更改尽可能地,我可以在Windows和Linux机器上运行服务器。



所有常见的类和方法(由CLIENT和SERVER使用)都存储在一个可以链接到CLIENT和SERVER的COMMONLIBRARY。



我将它全部放入Visual Studio 2010解决方案中:



客户端 - 客户端C#代码。

服务器 - 服务器C ++代码。

我还创建了一个公共库作为DLL项目 - COMMONLIBRARY



我将库创建为将生成DLL的C ++ CLASS LIBRARY。所以代码看起来像:



Hi all,

I´m developing a from scratch application that will have a client and a server. The client is being written with C# as a normal Windows application with forms and so forth. The server will receive TCP/IP socket messages for processing and respond.

I want the SERVER to be a C++ common code to be linked into Windows and Linux with less changes as possible, so that I can run the server on both Windows and Linux machines.

All the common classes and methods (used by CLIENT and SERVER) are being stored on a COMMONLIBRARY that can be linked to both CLIENT and SERVER.

I put it all into a Visual Studio 2010 solution:

CLIENT - The client C# code.
SERVER - The server C++ code.
I had also created a common library as a DLL project - COMMONLIBRARY

I created the library as a C++ CLASS LIBRARY that will generate a DLL. So the code look likes:

#pragma once

using namespace System;

namespace COMMONLIBRARY {

#include <string>

	public ref class clsLog
	{
	private:
		//
		// Properties
		//
		string	 m_strCurLogUser;
	public:
		// Methods
		int clsLog::Init (std::string FileName)
	};
}


#include <string>
class Foo
{
   string m_strMessage;
}



字符串类型无法识别。当我将std :: string添加为:




The string type is not being recognized. When I add std::string as:

std::string m_strCurLogUser;



然后我收到C4368错误 - 不支持混合类型。



如果我关闭公共语言运行时以使用标准C ++语言(att项目 - >属性),代码没有编译,有几个错误和内部库。



有人可以给出一些暗示吗?



在该环境中定义和使用字符串的最佳选择是什么?



如何让SERVER尽可能多地通用并将其绑定到Visual Studio环境?



任何帮助赞。



Rds



门德斯


Then I´m getting C4368 error - mixed types are not supported.

If I turn off "Common Language Runtime" to use the standard C++ language (att Project->properties), the code doesn´t compile with several errors and the internal libraries.

Can someone gimme a hint of what´s going on ?

What´s the best option to define and use strings on that environment ?

How can I get the SERVER as much generic as possible and tying it to the Visual Studio environment ?

Any help appreciated.

Rds

Mendes

推荐答案



namespace COMMONLIBRARY {

#include <string>
...
</string>





这是一个非常糟糕的主意,因为它试图将< string> 标题中的所有内容定义为 COMMONLIBRARY 名称空间。这可能看起来像一个简洁的想法,但相信我,它将无法奏效。在Windows环境中包含< string> 会带来数十个标题,包括 Windows.h 本身有效地重新定义了所有内容。命名空间内的Win32 API。

我会尝试在 COMMONLIBRARY 之外移动 #include 命名空间。





That''s a really bad idea as it tries to define everything in and included by the <string> header as being in the COMMONLIBRARY namespace. That might seem like a neat idea but believe me it will not work. Including <string> in a Windows environment brings in dozens of headers including Windows.h itself effectively redefining everything from the Win32 API inside the namespace.
I would try moving the #include outside the COMMONLIBRARY namespace.

#include <string>

namespace COMMONLIBRARY {
...
</string>


这篇关于通用C ++库unsing Visual Studio 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 04:34