473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

error when loading an old style dll

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.MarshalDirectiveEx ception' 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

Nov 20 '05 #1
6 1678
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 20 '05 #2
* "=?Utf-8?B?UGF1bA==?=" <an*******@discussions.microsoft.com> scripsit:
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.MarshalDirectiveEx ception' 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.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
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.
Nov 20 '05 #4
* "=?Utf-8?B?UGF1bA==?=" <an*******@discussions.microsoft.com> scripsit:
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'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet/>

..NET FAQs: <http://www.mvps.org/dotnet/dotnet/faqs/> (German)
Nov 20 '05 #5
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.
Nov 20 '05 #6
* "=?Utf-8?B?UGF1bA==?=" <an*******@discussions.microsoft.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet/>

..NET FAQs: <http://www.mvps.org/dotnet/dotnet/faqs/> (German)
Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: s_erez | last post by:
Hi, This is a realy tricky one. I have an ASP.NET application where some pages are reading data from a DB and presenting reports. In order for the user to wait while the page is reading data from...
3
by: Jacques Chaurette | last post by:
Hello all , thanks in advance for any help. While looking for a solution to how to replace the grey box while an applet loads, a search of Google got me an article by Glenn s. Peffers that claims to...
1
by: torbs | last post by:
I am trying to use the methods in quicktimes plugin, but IE generetes an error. I have tried to use the "document.all" instead of getElementById but the results remain the same. It won't recognise...
7
by: Shanimal | last post by:
Hello- I'm running a php front end app on mysql. When viewing the page with Firefox, no error. When viewing with IE6, always get the following error: Line: 210 Char: 3 Error: Object...
2
by: zino | last post by:
on windows XP and visual studio 2005, I cannot load a javascript or a style sheet file. when I try to run the aspx page I get a client side runtime error stating: " A Runtime error has occurred...
1
by: agatha.life | last post by:
I did a javascript for the loading of images (I didn't want to have the images loaded in "on loading" because they are too many). The website is for a model and if you look at the codeof pages (...
13
eragon
by: eragon | last post by:
JavaScript Loading Mask Requirements: Little knowledge in JavaScript and some HTML. JavaScript enabled browser. Applications: Useful for all those pages that load slow, and in sections, so...
2
by: tridirk | last post by:
Hi; I am getting a Objceted Expected Error on my forum site. I can't find what is wrong? Line: Char: Error: Object expected Code:0 the site is My SMF Forum
1
by: kailashchandra | last post by:
Below is my code.i want the first division should be load when window is loading. <HTML> <HEAD> <script> function tabFunc(getthis) { var getIn=getthis.innerHTML; var...
3
by: Leighya | last post by:
Im currently working on this xml file but when i load it to Mozilla, i got an error "Error Loading Stylesheet: Xpath parse failure: invalid variable name" It loads on IE properly. Only with the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.