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
{
[DllImport("User32.dll", EntryPoint = "MessageBox", CharSet = CharSet.Auto)]
public static extern int MsgBox(int hWnd, String text, String caption, uint type);
[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);
}
}
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.