Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have a VB6 program that call a dll. I'm converting the program to c.net 2010. I'm building under x86. The dll was created with PowerBasic.

VB6 Code

Declare Function trm_Open Lib "TRM.DLL" (PathFileName As String, MultiUser As Long) As Long

UidFileName = "c:\user.trm"
multiUserMode = 1
hUidFile = trm_Open(UidFileName, multiUserMode)

c.net 2010

[DllImport(@"TRM.DLL")]
static extern int trm_Open(string pathFileName, int nMultiUser);
public int trmOpen(string pathFileName, int nMultiUser)
{
return trm_Open(pathFileName, nMultiUser);
}


string filename = "c:\user.trm";
int mu=1 ;
rtc = trmOpen(filename, mu);


I'm getting this error.
An unhandled exception of type 'System.DllNotFoundException' occurred in trmtest1.exe

Additional information: Unable to load DLL 'TRM.DLL': Invalid access to memory location. (Exception from HRESULT: 0x800703E6)

Thanks,
Mark
Posted
Comments
Sergey Alexandrovich Kryukov 22-May-13 18:26pm    
What is "c.net"?!
—SA
CodeMark9 23-May-13 9:18am    
visual studio c sharp .net 2010

1 solution

Place "TRM.DLL" in the output folder of your application, try again.

—SA
 
Share this answer
 
Comments
CodeMark9 23-May-13 9:17am    
I tried that and it did not work. I also put the path [DllImport(@"c:\TRM.DLL")] and did not work.
Sergey Alexandrovich Kryukov 23-May-13 9:21am    
Another problem may be the string type. By default, P/Invoke marshals unmanaged string as a null-terminated string, and I don't know what is it in your case. You need to use [MarshalAs] for the string parameter to specify assumed unmanaged string type exactly.
—SA
CodeMark9 23-May-13 9:47am    
static extern int trm_Open([MarshalAs(UnmanagedType.AnsiBStr)] string PathFileName, int nMultiUser); Is this what you where think I need to do. It did not work. Any other ideas?
Sergey Alexandrovich Kryukov 23-May-13 12:51pm    
Are you sure that AnsiBStr is what your version of Basics uses? I just don't know. By the way, if is of course not nice of me to give you such a dirty advice, but: you can simply try out all standard string types. :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900