无法找到我的本机DLL(错误代码0x8007007E) [英] Unable to Find my Native DLL (Error Code 0x8007007E)
问题描述
Hello Experts,
我创建了一个Native Dll(myNativeDll.dll)只是为了保持简单,它暴露了一种方法。
__declspec(dllexport)char * GetStringFromDll()
{
const size_t alloc_size = 128;
STRSAFE_LPSTR结果=(STRSAFE_LPSTR)CoTaskMemAlloc(alloc_size);
STRSAFE_LPCSTR retstr =此值从本机dll返回;
StringCchCopyA(结果,alloc_size,retstr);
返回(char *)结果;
}
客户端(托管应用程序)定义了一个帮助类来使用这个dll作为
Hello Experts,
I have created a Native Dll (myNativeDll.dll) just to keep it simple it exposes one method.
__declspec(dllexport)char * GetStringFromDll( )
{
const size_t alloc_size = 128;
STRSAFE_LPSTR result = (STRSAFE_LPSTR)CoTaskMemAlloc( alloc_size );
STRSAFE_LPCSTR retstr = "This value is returned from native dll";
StringCchCopyA( result, alloc_size, retstr );
return (char *) result;
}
on the client side (Managed App) defined a helper class to use this dll as
namespace MarshalStringApp
{
public class MyDllWrapper
{
// Calling Standard Windows Functions.
[DllImport("User32.dll", EntryPoint = "MessageBox", CharSet = CharSet.Auto)]
public static extern int MsgBox(int hWnd, String text, String caption, uint type);
// Calling Functions from our Dll.
[DllImport("myNativeDll.dll")]
public static extern String GetStringFromDll();
}
}
并在表单中添加了一个处理程序来调用此函数。
and added a handler to the form to call this function.
private void btnGetStringFromDll_Click(object sender, EventArgs e)
{
String str = "";
try
{
str = MyDllWrapper.GetStringFromDll();
MessageBox.Show("String Returned [" + str + "]");
}
catch (Exception eX)
{
MessageBox.Show(eX.Message);
}
}
我收到异常代码(0x8007007E),提示DLLmyNativeDll.dll 找不到,我试着把它复制到客户端的文件夹(exe所在的地方),但没有用。我应该在哪里复制这个本机dll,让这个应用程序工作。或者我错过了什么。
任何帮助都将受到高度赞赏。
-prateek。
I am getting an exception Code (0x8007007E), suggesting that DLL "myNativeDll.dll" is not found, i tried copying it to the client's folder to (where exe resides) but no avail. where should i copy this native dll, for this app to work. or i am missing something.
any help will be highly appreciated.
-prateek.
推荐答案
最快的解决方案是将此dll放在WINDOWS \SYSTEM32文件夹中,看看它是否被加载。
Quickest solution is to put this dll in WINDOWS\SYSTEM32 folder and see whether it gets loaded or not.
这篇关于无法找到我的本机DLL(错误代码0x8007007E)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!