473,386 Members | 1,752 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,386 software developers and data experts.

Calling known functions in an unknown DLL

JB
I have an aplication which used to be created in Delphi 5. For various
reasons we want to try to recode that in vb .net but the original
application called functions inside one or more dlls that were loaded
dynaically by the name found at run time.

i.e. what would happen is that the application would start, it finds
all the *.dll functions available in a specified subdirectory.
The user would then select one target platform which corresponds to
one DLL from the found DLL list
That DLL is then loaded dynamically and used by the application.

The rationale is that the application then automatically picks up new
target platforms simply by adding the DLL to the appropriate
directory.

I am having problems trying to get this to run in vb .net. I can get a
single DLL to work but have to explicitly name the DLL in the source
code. In delphi I would call LoadLib and GetProcAddress and then cast
the result of GetProcAddress to a pointer to a function which would
then be used by the application. Very simple and it works. This
appears to be impossible in VB .net

Is there any way to achieve this?

Nov 21 '05 #1
3 2137
>Is there any way to achieve this?

Yes, here's one way

http://www.msjogren.net/dotnet/eng/s...dynpinvoke.asp
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2
i did something simular in the past with VB6
i created several different activex dll`s with different content ( language
dependant versions , plugins ) however with all the same interface
on startup the program searched for the right dll did a create object on it
and it run just fine

well this can also be done with .Net if you investigate remoting you will
see that a simular concept is there also beeing used ( interface based )

regards

Michel Posseth

"JB" <th********@somewhere.else> wrote in message
news:bq********************************@4ax.com...
I have an aplication which used to be created in Delphi 5. For various
reasons we want to try to recode that in vb .net but the original
application called functions inside one or more dlls that were loaded
dynaically by the name found at run time.

i.e. what would happen is that the application would start, it finds
all the *.dll functions available in a specified subdirectory.
The user would then select one target platform which corresponds to
one DLL from the found DLL list
That DLL is then loaded dynamically and used by the application.

The rationale is that the application then automatically picks up new
target platforms simply by adding the DLL to the appropriate
directory.

I am having problems trying to get this to run in vb .net. I can get a
single DLL to work but have to explicitly name the DLL in the source
code. In delphi I would call LoadLib and GetProcAddress and then cast
the result of GetProcAddress to a pointer to a function which would
then be used by the application. Very simple and it works. This
appears to be impossible in VB .net

Is there any way to achieve this?

Nov 21 '05 #3
JB wrote:
I have an aplication which used to be created in Delphi 5. For various
reasons we want to try to recode that in vb .net but the original
application called functions inside one or more dlls that were loaded
dynaically by the name found at run time. Is there any way to achieve this?


One way would be to have each .dll implement a certain interface that
defines what method needs to be called. For example:

Public Interface IPlatform
Sub Execute(...)
End Interface

Then a class in the .dll will implement the interface:

Public Class Platform1
Implements IPlatform

Public Sub Execute(...) Implements IPlatform.Execute
'Code to execute here
End Sub
End Class

Then the app that loads the .dll's can get a list of all the .dll's in
the folder, examine each one to see if it implements the IPlatform
interface and if so, instantiate the class and call the Execute method.

One caveat is that loading the assembly to check for the presence of
the interface will load the assembly and it will stay loaded until the
app shuts down. You could potentially load up many of the .dll's and
have them hanging around not being used. In .Net 2.0, there's a way to
load the assembly just for inspecting it so this is not a problem. In
1.1, you can load the assemblies in a new AppDomain and then unload the
AppDomain to unload the assemblies.

Good luck.

Nov 21 '05 #4

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

Similar topics

8
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
19
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const...
1
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code...
13
by: santosh | last post by:
Hi, If I call free() with a uninitialised pointer, will the program state become undefined, or will free() return harmlessly? Incidentally, is there a way in Standard C to determine weather a...
2
by: Daniel Lidström | last post by:
I'm using a library called fyba. This library reads and writes files in a format called sosi. fyba uses the following code to determine if the calling process has own methods to handle errors,...
18
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
61
by: Ron Ford | last post by:
K&R has three different versions of qsort, and the ultimate one is supposed to be like the one in the std library. I'm trying to implement the first, which is in §4.10. I think I'm pretty close...
2
by: unauthorized | last post by:
The short story: I need to be able to cast a function pointer for any function and class to an intermediate type, so I could call it from any point of my program using the "__asm call" instruction....
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.