Tag: extern

function别名

我想从kernel32.dll导入一些函数,但我想使用不同的名称。 function示例: [DllImport(“kernel32.dll”)] private static extern bool ReadProcessMemoryProc64 (…); private static bool BetterReadableAndWriteableName (…) { ReadProcessMemoryProc64(…); } 如果有另一种方式,包装该function是我实际上不想要的。

如何为System.Core创建一个extern别名?

在我的项目中,我绝对需要System.Core的外部别名。 不幸的是,在.Net 4.0项目中,你甚至无法添加对System.Core的引用,因为显然,构建系统默认包含它。 有没有人知道如何强制系统让我为这个lib指定一个extern别名? 谢谢!

C ++ / CLI-> C#错误C2526:C连接函数无法返回C ++类

我有一个使用VS2010 C#构建的简单.NET dll,它暴露了一个类的2个静态成员 public class Polygon { public static void Test(int test) {} public static void Test(List test) {} } 然后我从VS2010 C ++创建了一个Console应用程序,并在_tmain上面添加了这个函数 extern “C” void TestMe() { Polygon::Test(3); } 添加引用和编译会给我这个错误 1>WierdError.cpp(9): error C2526: ‘System::Collections::Generic::List::GetEnumerator’ : C linkage function cannot return C++ class ‘System::Collections::Generic::List::Enumerator’ 1> with 1> [ 1> T=int 1> ] 1> WierdError.cpp(9) : […]

如何设置C ++函数以便p / invoke可以使用它?

希望这是一个无脑的简单问题,但它表明我缺乏C ++的专业知识。 我是一名C#程序员,过去我和其他人的C ++ / C dll一起完成了P / Invoke的大量工作。 但是,这次我决定自己编写一个包装器C ++ DLL(非托管),然后从C#调用我的包装器dll。 我遇到的问题是我无法定义可以通过p / invoke找到的C ++函数。 我不知道这是什么语法,但这是我到目前为止所做的: extern bool __cdecl TestFunc() { return true; } 最初我只是有这个,但它也没有用: bool TestFunc() { return true; } 然后在C#方面,我有: public const string InterfaceLibrary = @”Plugins\TestDLL.dll”; [DllImport( InterfaceLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = “TestFunc” ), SuppressUnmanagedCodeSecurity] internal static extern bool TestFunc(); 所有东西都编译,但是当我执行这个C#p […]

“无法在dll中找到名为的入口点”(c ++到c#类型转换)

我有一个来自第三方的dll,它是用C ++编写的。 以下是来自dll文档的一些信息: //start documentation RECO_DATA{ wchar_t Surname[200]; wchar_t Firstname[200]; } 描述:用于接收function结果的数据结构。 所有function结果将存储为Unicode(UTF-8)。 方法: bool recoCHN_P_Name(char *imgPath,RECO_DATA *o_data); 输入: char * imgPath 此function识别的图像位置的完整路径 RECO_DATA * o_data 用于接收function结果的数据对象。 函数返回:如果成功则返回true,否则返回false。 //end documentation 我试图从我的C#应用​​程序调用recoCHN_P_Name。 为此,我想出了这段代码: 导入dll的代码: public class cnOCRsdk { [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct RECO_DATA{ [MarshalAs(UnmanagedType.ByValTStr, SizeConst=200)] public string FirstName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 200)] public string […]

C#:在shlwapi.dll中实现或替代StrCmpLogicalW

对于我的应用程序中的自然排序,我目前在shlwapi.dll中调用一个名为StrCmpLogicalW的函数。 我正在考虑尝试在Mono下运行我的应用程序,但当然我不能拥有这个P / Invoke的东西(据我所知)。 是否有可能在某处看到该方法的实现,或者是否有一个好的,干净且高效的C#片段可以做同样的事情? 我的代码目前看起来像这样: [SuppressUnmanagedCodeSecurity] internal static class SafeNativeMethods { [DllImport(“shlwapi.dll”, CharSet = CharSet.Unicode)] public static extern int StrCmpLogicalW(string psz1, string psz2); } public class NaturalStringComparer : IComparer { private readonly int modifier = 1; public NaturalStringComparer() : this(false) {} public NaturalStringComparer(bool descending) { if (descending) modifier = -1; } public int Compare(string […]