473,406 Members | 2,467 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.

Can't get PInvoke to work

I'm trying unsuccessfully to access some functions within an external
DLL; sorry I don't know much about DLL classification, but AFAIK it's
not an ActiveX DLL, but a vanilla one written probably in C.

I've copied the DLL to my project folder (mydll.dll), but beyond that
haven't added any reference to it because I can't see how and don't
know if I need to anyhow.

My class code consists of (just one function as an example):

Imports System.Runtime.InteropServices
Public Class VPWLIO
<DllImport("mydll")> _
Public Shared Function OpenCommPort_V(ByVal comport As Int16,
ByVal baudrate As Integer) As Int16

End Function
End Class

(Sorry the word wrap has broken the lines a little)

I can instantiate this class OK in the calling module and Intellisense
shows up the method so that part's OK. But on running the project I
get an error that the DLL can't be loaded.

This is the first time I've tried to do this and so I'm probably
making some fundamental mistake, but can anyone shed any further light
please?

NB The function name inside the DLL is documented to be exactly how
I've spelled it in the function definition.

TIA
JGD
Nov 20 '05 #1
4 1089
On Tue, 10 Feb 2004 09:49:08 +0000, John Dann <ne**@prodata.co.uk>
wrote:
I can instantiate this class OK in the calling module and Intellisense
shows up the method so that part's OK. But on running the project I
get an error that the DLL can't be loaded.


Sorry could have been a little more explicit - the actual error is a
DLLNotFoundException. So presumably my project can't see the DLL even
though it's in the project folder - perhaps there _is_ something more
I should be doing to make the DLL visible.

NB The project is saved on to a remote network folder, but this folder
has been given FullTrust status and saves the projects OK. But is
there some reason why it might not load a DLL from such a location?

JGD
Nov 20 '05 #2
OK, problem solved - I think. For development purposes the DLL seems
to need to be in the \bin subfolder of the project folder - perhaps
not surprising on reflection. The test function now appears to work
OK.

JGD
Nov 20 '05 #3
Your dll should be in the EXE's path or in the system32 folder.

"John Dann" <ne**@prodata.co.uk> wrote in message
news:1t********************************@4ax.com...
On Tue, 10 Feb 2004 09:49:08 +0000, John Dann <ne**@prodata.co.uk>
wrote:
I can instantiate this class OK in the calling module and Intellisense
shows up the method so that part's OK. But on running the project I
get an error that the DLL can't be loaded.


Sorry could have been a little more explicit - the actual error is a
DLLNotFoundException. So presumably my project can't see the DLL even
though it's in the project folder - perhaps there _is_ something more
I should be doing to make the DLL visible.

NB The project is saved on to a remote network folder, but this folder
has been given FullTrust status and saves the projects OK. But is
there some reason why it might not load a DLL from such a location?

JGD

Nov 20 '05 #4
Hi,

isn't also a good idea to check and if not, register the dll in the system
within your app startup sequence. That way you can put wherever you like
As I recall it the *.exe looks for the *.dll in its 'own' folder, the
windows\system32 folder and if it has been registered?.

For testing I put the *.dll in the *exe folder, and when shipping I make
sure that the *.dll is registered with the installation app.

/anders

"Abubakar" <em**********@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Your dll should be in the EXE's path or in the system32 folder.

"John Dann" <ne**@prodata.co.uk> wrote in message
news:1t********************************@4ax.com...
On Tue, 10 Feb 2004 09:49:08 +0000, John Dann <ne**@prodata.co.uk>
wrote:
I can instantiate this class OK in the calling module and Intellisense
shows up the method so that part's OK. But on running the project I
get an error that the DLL can't be loaded.


Sorry could have been a little more explicit - the actual error is a
DLLNotFoundException. So presumably my project can't see the DLL even
though it's in the project folder - perhaps there _is_ something more
I should be doing to make the DLL visible.

NB The project is saved on to a remote network folder, but this folder
has been given FullTrust status and saves the projects OK. But is
there some reason why it might not load a DLL from such a location?

JGD


Nov 20 '05 #5

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

Similar topics

4
by: Ted | last post by:
Is it possible to use mailslots in .NET using PInvoke? I have a VC++ 6.0 based app that creates and listens to a mailslot. I have a second VC++ 6.0 based app that opens the mailslot and writes...
42
by: Mike P. | last post by:
Hello I come from the world of C++ programming, and I'm used to writing programs that are actually executed by the CPU, and that run with some semblance of performance. I have taken the time to...
3
by: Brett Robichaud | last post by:
I have created a simple background thread to make one pinvoke call into a DLL I've created. My Winforms app spawns the thread in the form load event then go about it's business. The problem is...
10
by: Steve | last post by:
I want to make a web application that will run on my home server and would like to be able to have the web application interact with another, winforms application. For example, let's say I wanted...
3
by: Mike | last post by:
I have been banging my head againt my desk for a couple days now and nothing I try seems to work. I know I am missing something small and it's killing me. This is the error I am getting with...
6
by: Pucca | last post by:
I have a program that originally compiles into a exe file. I changed the compile option to generate dll file. This program calls a com component. Can I use pinvoke in C# to call it? The...
7
by: Rymfax | last post by:
I would really appreciate it if someone could help me figure out what I'm doing wrong trying to PInvoke SetupDiEnumDriverInfo. All the other PInvokes i've done up to this point work fine. Whenver...
6
by: Karthik V | last post by:
In a certain dll, there is this function: typedef DWORD STDAPICALLTYPE SOMEFUNC(VOID *pHandle, IProgress *pProgress); where IProgress is class IProgress { public: virtual void Update(UINT...
5
by: =?Utf-8?B?SmVzc2ljYQ==?= | last post by:
Hello, I have a pInvoke question. This is the C function that is exported from one of the C dll, extern __declspec(dllexport) IM_RET_CODE ST_import (IM_MODE mode, char *filename,...
4
by: Sagaert Johan | last post by:
Hi I am struggling with pinvoke I have dll a function that is declared as : sf_command (IntPtr sndfile,int command, IntPtr data, int datasize); i need to pass a pointer to a double in 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.