error when loading an old style dll

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi I am just trying to load an old style dll, not trying to pass anything to it yet but get the error below
An unhandled exception of type 'System.Runtime.InteropServices.MarshalDirectiveException' occurred in dll_test.ex
Additional information: PInvoke restriction: can not return variants
It is a c dll
Here is the cod
Imports System.Runtime.InteropService

Public Class Win32_reduc
Declare Auto Function test Lib "lzo.dll" (
End Clas

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
Win32.MessageBox(0, "Hello World", "Platform Invoke Sample", 0
Win32_reduce.test(
End Su
The error occures on the Win32_reduce.test() lin
THanks Paul
 
Paul,
Declare Auto Function test Lib "lzo.dll" ()

Since you don't specify any return type it defaults to Object which is
marshaled as a VARIANT. If you don't want any return type you should
use a Sub rather than a Function.

You can avoid these type of problems by turning on Option Strict.



Mattias
 
* "=?Utf-8?B?UGF1bA==?= said:
Hi I am just trying to load an old style dll, not trying to pass anything to it yet but get the error below.
An unhandled exception of type 'System.Runtime.InteropServices.MarshalDirectiveException' occurred in dll_test.exe
Additional information: PInvoke restriction: can not return variants.
It is a c dll.
Here is the code
Imports System.Runtime.InteropServices

Public Class Win32_reduce
Declare Auto Function test Lib "lzo.dll" ()

Explicitly specify the datatype of the function's return value.
 
I tried declaring it as sub as shown below and it could not load it
Declare Auto Sub test Lib "lzo.dll" ()
error is An unhandled exception of type 'System.DllNotFoundException' occurred in dll_test.ex

Additional information: Unable to load DLL (lzo.dll)
stack inf
dll_test.exe!dll_test.Form1.Form1_Load(Object sender = {dll_test.Form1}, System.EventArgs e = {System.EventArgs}) Line 64 + 0x6 bytes Basi
I probably need to specify the return type as you mentioned, is there anyway that the .net environment can automatically tell what the input and output data types are for the dll or is there anyway to view its code to find out? I currently do not have the source code, just the dll. It is a C dll. Thanks Paul.
 
* "=?Utf-8?B?UGF1bA==?= said:
I tried declaring it as sub as shown below and it could not load it,
Declare Auto Sub test Lib "lzo.dll" ()
error is An unhandled exception of type 'System.DllNotFoundException' occurred in dll_test.exe

Additional information: Unable to load DLL (lzo.dll).

Have a look at the documentation or the header files, maybe you will
find the information there.

If you don't have any documentation, you can /try/ to declare the return
value as 'Int32'.
 
Hi thanks for the response. I tried the INT32 got it to build ok but still having errors, probably need to find out what the dll is expecting and what it returns, datatypes. Paul. Seem to either get the load error or the Variant return error.
 
* "=?Utf-8?B?UGF1bA==?= said:
Hi thanks for the response. I tried the INT32 got it to build ok but
still having errors, probably need to find out what the dll is expecting
and what it returns, datatypes. Paul.

ACK. Try to find a documentation.
 
Back
Top