小编McA*_*Lee的帖子

如何在Debug与Release之间进行不同的编译?

我是C#的新手,在编译C#项目时遇到问题.它是关于Debug和Release模式下的调试日志.我希望在调试模式下调用日志函数,但不要在发布模式下调用,同时考虑性能.我知道在C/C++中,这很容易做到:

// this is C/C++ sample, not C#
#ifdef DEBUG
#define DebugLog(CString,__VA_ARGS__) LogFunction(CString,__VA_ARGS__)
#else
#define DebugLog
#endif
Run Code Online (Sandbox Code Playgroud)

在上面的C/C++代码中,DebugLog()在Debug模式下编译和调用,但在Release模式下不编译或调用,因此可以确保性能.

C#中是否有与上述C/C++代码类似的东西?

c# debugging release compilation

14
推荐指数
2
解决办法
1万
查看次数

C++ dll返回的字符串在C#调用者中被破坏了,为什么?

我有一个调用C++ DLL的C#应用​​程序.

在C#中,我的代码如下:

[DllImport(@"111.dll", CharSet = CharSet.Unicode)]
public extern static String Func1(String arg);
......
String arg = "test text";
String retstring = Func1(arg);
Run Code Online (Sandbox Code Playgroud)

在CPP中,我的功能定义如下:

extern "C"
{
__declspec(dllexport) LPWSTR Func1(LPWSTR arg)
{
          ....
          LPWSTR ret1 = L"1?2?3?4?5";
          LPWSTR ret2 = SomeActualFunction(arg);
          retturn ret1; // return ret2;
     }
}
Run Code Online (Sandbox Code Playgroud)

如果我在C++的Func1()中返回ret1,一切正常.在VS2008的内存窗口中,我可以看到正确的Unicode二进制文件.在C++中,ret1的二进制文件是

"31 00 3f 00 32 00 3f 00 33 00 3f 00 34 00 3f 00 35 00"

在C#中,retstring的二进制文件是

"28 67 a3 f7 fe 07 00 00 0a 00 00 00 …

c# c++ string dll return

6
推荐指数
2
解决办法
2501
查看次数

标签 统计

c# ×2

c++ ×1

compilation ×1

debugging ×1

dll ×1

release ×1

return ×1

string ×1