473,396 Members | 2,011 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,396 software developers and data experts.

Calling API functions dynamically?

I need to be able to call the same API function from VB, which will
reside in different DLLs. While all of the functions have the same
signature and name, DLL file names are not known at compile time.
Therefore, my assumption that using Declare statement or DllImport
attribute is NOT an option in such a case.

I can use LoadLibrary() and GetProcAddress() from Kernel32 to get the
addreses, but is there a way to actually call an API method by its
address from VB? Or can anyone suggest anything else?

TIA!
May 22 '06 #1
46 3713
Usenet*User <**@*.**> schrieb im Beitrag
<ta********************************@4ax.com>...
I need to be able to call the same API function from VB, which will
reside in different DLLs. While all of the functions have the same
signature and name, DLL file names are not known at compile time.
Therefore, my assumption that using Declare statement or DllImport
attribute is NOT an option in such a case.

I can use LoadLibrary() and GetProcAddress() from Kernel32 to get the
addreses, but is there a way to actually call an API method by its
address from VB? Or can anyone suggest anything else?


I can think of two ways:

a) Build and use a standard DLL (C(++)) which redirects the function call
to the respective DLL.

b) Add a declare statement with a - more or less :-) - unique library file
name. Then, before calling the library function, make a copy of the
original library and name it with this unique file name. The copy of the
library of course has to be located somewhere where the OS can find it.

--
----------------------------------------------------------------------
THORSTEN ALBERS Universität Freiburg
albers@
uni-freiburg.de
----------------------------------------------------------------------

May 22 '06 #2
Usenet User wrote:
I need to be able to call the same API function from VB, which will
reside in different DLLs. While all of the functions have the same


Why would you do this? Are you trying to create some sort of "plugin"
architecture? Do you have control over the .dll you are trying to call
or are they 3rd party?

Perhaps you could create a single class in which you pass the name of
the .dll as a string and then inside the class, call the api method
based on that string.

Good luck

May 22 '06 #3
cant you just use
CallByName "Msgbox('Hello World')"

May 22 '06 #4
On Mon, 22 May 2006 10:59:48 -0700, Usenet*User <**@*.**> wrote:
I need to be able to call the same API function from VB, which will
reside in different DLLs. While all of the functions have the same
signature and name, DLL file names are not known at compile time.
Therefore, my assumption that using Declare statement or DllImport
attribute is NOT an option in such a case.

I can use LoadLibrary() and GetProcAddress() from Kernel32 to get the
addreses, but is there a way to actually call an API method by its
address from VB? Or can anyone suggest anything else?


Another way (hack) is to use the function address obtained with
GetProcAddress with CallWindowProc. The catch here (big catch) is the
function being called needs to take exactly 4 32-bit args or you'll
hose the stack. There are ways around that limitation (using
~assembly~ opcodes to restore the stack). Matt Currland's book
"Advanced VB6" covers the technique. Definitely not for the feint of
heart - pure voodoo IMO <g>
-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
May 22 '06 #5
hi Usenet,

There are two pre-programmed, pre-digested solutions to this.

1. My favorite, written by Arkadiy Olovyannikov, and called:
"Call API functions by Name, without Declare", can be found
on the freevbcode website:

http://www.freevbcode.com/ShowCode.Asp?ID=1863

2. However, the api newsgroupies here may be expected to heap
disrespect on Arkadiy's code. They have asserted that the only
"real" legitimate appropriate code to do this was written by
Matthew Curland. There is an article by Curland on this subject,
originally published in "Visual Basic Programmer's Journal",
and now available on the web, entitled: "Call Function Pointers".

http://www.fawcette.com/archives/lis...agIssueId=265#

Also, if you have $40 in spare change, (and you can still find it)
you may purchase Curland's book "Advanced Visual Basic 6", and you
will find the same "Call Function Pointers" code in there.

cheers, jw
__________________________________________________ __________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)

Usenet wrote:
I need to be able to call the same API function from VB, which will
reside in different DLLs. While all of the functions have the same
signature and name, DLL file names are not known at compile time.
Therefore, my assumption that using Declare statement or DllImport
attribute is NOT an option in such a case.

I can use LoadLibrary() and GetProcAddress() from Kernel32 to get the
addreses, but is there a way to actually call an API method by its
address from VB? Or can anyone suggest anything else?

TIA!

May 22 '06 #6
Matt's book still appears to be available through
http://service.bfast.com/bfast/click...8&bfmtype=book

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.


"mr_unreliable" <ki********************@notmail.com> wrote in message
news:%2***************@TK2MSFTNGP03.phx.gbl...
hi Usenet,

There are two pre-programmed, pre-digested solutions to this.

1. My favorite, written by Arkadiy Olovyannikov, and called:
"Call API functions by Name, without Declare", can be found
on the freevbcode website:

http://www.freevbcode.com/ShowCode.Asp?ID=1863

2. However, the api newsgroupies here may be expected to heap
disrespect on Arkadiy's code. They have asserted that the only
"real" legitimate appropriate code to do this was written by
Matthew Curland. There is an article by Curland on this subject,
originally published in "Visual Basic Programmer's Journal",
and now available on the web, entitled: "Call Function Pointers".

http://www.fawcette.com/archives/lis...agIssueId=265#

Also, if you have $40 in spare change, (and you can still find it)
you may purchase Curland's book "Advanced Visual Basic 6", and you
will find the same "Call Function Pointers" code in there.

cheers, jw
__________________________________________________ __________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)

Usenet wrote:
I need to be able to call the same API function from VB, which will
reside in different DLLs. While all of the functions have the same
signature and name, DLL file names are not known at compile time.
Therefore, my assumption that using Declare statement or DllImport
attribute is NOT an option in such a case.

I can use LoadLibrary() and GetProcAddress() from Kernel32 to get the
addreses, but is there a way to actually call an API method by its
address from VB? Or can anyone suggest anything else?

TIA!


May 22 '06 #7
> Matt's book still appears to be available through
http://service.bfast.com/bfast/click...8&bfmtype=book


It's a little bit cheaper here...

http://www.amazon.com/gp/product/020...Fencoding=UTF8

Rick
May 23 '06 #8
<aa*********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
cant you just use
CallByName "Msgbox('Hello World')"
No

May 23 '06 #9
"mr_unreliable" <ki********************@notmail.com> wrote in message
news:%2***************@TK2MSFTNGP03.phx.gbl...
hi Usenet,

There are two pre-programmed, pre-digested solutions to this.

1. My favorite, written by Arkadiy Olovyannikov, and called:
"Call API functions by Name, without Declare", can be found
on the freevbcode website:

http://www.freevbcode.com/ShowCode.Asp?ID=1863
I downloaded this code and much to my suprise it was a modification to some
code I put on the net many years ago. I don't see anything wrong with the
method except it could be optimised not to build the assembly code for each
call in this function:

Public Function CallFunction(ParamArray FuncParams()) As Long
Dim i As Long
If m_lpFn = 0 Then
MsgBox "Function not defined!", vbCritical, "Call function error"
Exit Function
End If
ReDim m_abCode(0)
ReDim m_lParameters(UBound(FuncParams) + 1)
ReDim m_abCode(18 + 32 + 6 * UBound(m_lParameters))
For i = 1 To UBound(m_lParameters)
m_lParameters(i) = CLng(FuncParams(i - 1))
Next i
CallFunction = CallWindowProc(PrepareCode, 0, 0, 0, 0)
m_lpFn = 0
End Function
2. However, the api newsgroupies here may be expected to heap
disrespect on Arkadiy's code. They have asserted that the only
"real" legitimate appropriate code to do this was written by
Matthew Curland. There is an article by Curland on this subject,
originally published in "Visual Basic Programmer's Journal",
and now available on the web, entitled: "Call Function Pointers".


I don't see how matthew's method would be any less hacky. I can't see it
though as that page requires a login.

Michael
May 23 '06 #10
"Usenet User" < @ . > wrote in message
news:ta********************************@4ax.com...
I need to be able to call the same API function from VB, which will
reside in different DLLs. While all of the functions have the same
signature and name, DLL file names are not known at compile time.
Therefore, my assumption that using Declare statement or DllImport
attribute is NOT an option in such a case.

I can use LoadLibrary() and GetProcAddress() from Kernel32 to get the
addreses, but is there a way to actually call an API method by its
address from VB? Or can anyone suggest anything else?


If your dlls have the same name but diff dir just use LoadLibrary and
FreeLibrary with the standard vb6 declare, eg

Declare Function Whatever Lib "MyDLL" ....
Sub DoIt()
lib = LoadLibrary("C:\abc\MyDll.dll")
WhatEver(....)
FreeLibrary(lib)
End Sub

because a library of name MyDLL is already loaded vb6 will just use that.
Just make sure you match the no of loadlib calls with freelib and don't call
your function without calling LoadLibrary at least once somewhere in code.

Michael
May 23 '06 #11
Michael C wrote:
2. However, the api newsgroupies here may be expected to heap
disrespect on Arkadiy's code. They have asserted that the only
"real" legitimate appropriate code to do this was written by
Matthew Curland. There is an article by Curland on this subject,
originally published in "Visual Basic Programmer's Journal",
and now available on the web, entitled: "Call Function Pointers".


I don't see how matthew's method would be any less hacky. I can't see
it though as that page requires a login.


http://www.BugMeNot.com <- HTH!
--
Working without a .NET?
http://classicvb.org/
May 23 '06 #12
"Karl E. Peterson" <ka**@mvps.org> wrote in message
news:uZ**************@TK2MSFTNGP03.phx.gbl...
I don't see how matthew's method would be any less hacky. I can't see
it though as that page requires a login.


http://www.BugMeNot.com <- HTH!


Considering what I have seen of matt's I'd imagine it would be significantly
more hacky.

Michael
May 23 '06 #13
"Karl E. Peterson" <ka**@mvps.org> wrote in message
news:uZ**************@TK2MSFTNGP03.phx.gbl...
I don't see how matthew's method would be any less hacky. I can't see
it though as that page requires a login.


http://www.BugMeNot.com <- HTH!


Ok, I had a look at his code. It shoves assembly code into a currency
variable and does pretty much the same thing but requires the extra
complexity of creating and referencing a typelib (presumably a new typelib
for each different call signature). It also has the reduced flexibility of
not being able to call cdecl functions. Matt has a bad habit of
overcomplicating things. But then again karl, don't let logic get in your
way. :-)

Michael
May 23 '06 #14
On Tue, 23 May 2006 12:17:36 +1000, "Michael C" <no****@nospam.com>
wrote:
in <OH**************@TK2MSFTNGP02.phx.gbl>
"Karl E. Peterson" <ka**@mvps.org> wrote in message
news:uZ**************@TK2MSFTNGP03.phx.gbl...
I don't see how matthew's method would be any less hacky. I can't see
it though as that page requires a login.


http://www.BugMeNot.com <- HTH!


Ok, I had a look at his code. It shoves assembly code into a currency
variable and does pretty much the same thing but requires the extra
complexity of creating and referencing a typelib (presumably a new typelib
for each different call signature). It also has the reduced flexibility of
not being able to call cdecl functions. Matt has a bad habit of
overcomplicating things. But then again karl, don't let logic get in your
way. :-)

Michael


You must be one of those irreverent dot net freaks that think you can
easily discredit someone who spent years building their reputation
simply by virtue of vomiting your spew.

m$' latest piece of f**k doesn't qualify you to make those allegations
but I must admit you do provide great comic relief for those who are
more discerning in what they read and believe.

Thanks for the laughs hyena.

---
This posting is provided "AS IS" with no warranties and no guarantees either express or implied.

Stefan Berglund
May 23 '06 #15
"Stefan Berglund" <so**************@for.me> wrote in message
news:dd********************************@4ax.com...
You must be one of those irreverent dot net freaks that think you can
easily discredit someone who spent years building their reputation
simply by virtue of vomiting your spew.

m$' latest piece of f**k doesn't qualify you to make those allegations
but I must admit you do provide great comic relief for those who are
more discerning in what they read and believe.

Thanks for the laughs hyena.


What on earth are you talking about. I did not mention dot net at all in
this thread. Was the link karly posted something about dot net?

I was commenting on matt curland's method of calling a function pointer in
vb6.

Michael
May 23 '06 #16

"mr_unreliable" <ki********************@notmail.com> wrote in message
news:%2***************@TK2MSFTNGP03.phx.gbl...
hi Usenet,

There are two pre-programmed, pre-digested solutions to this.

1. My favorite, written by Arkadiy Olovyannikov, and called:
"Call API functions by Name, without Declare", can be found
on the freevbcode website:

http://www.freevbcode.com/ShowCode.Asp?ID=1863

2. However, the api newsgroupies here may be expected to heap
disrespect on Arkadiy's code. They have asserted that the only
"real" legitimate appropriate code to do this was written by
Matthew Curland. There is an article by Curland on this subject,
originally published in "Visual Basic Programmer's Journal",
and now available on the web, entitled: "Call Function Pointers".

http://www.fawcette.com/archives/lis...agIssueId=265#

Also, if you have $40 in spare change, (and you can still find it)
you may purchase Curland's book "Advanced Visual Basic 6", and you
will find the same "Call Function Pointers" code in there.

Both of these approaches have a serious draw back. They require that a
small piece of assembly be used to thunk the call. Problem is that this
little piece of assembly resides in memory allocated as data. Back when
these approaches were originally written that wasn't a problem. Today
though a machine running with DEP turned on will kill any process trying to
do this.
cheers, jw
__________________________________________________ __________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)

Usenet wrote:
I need to be able to call the same API function from VB, which will
reside in different DLLs. While all of the functions have the same
signature and name, DLL file names are not known at compile time.
Therefore, my assumption that using Declare statement or DllImport
attribute is NOT an option in such a case.

I can use LoadLibrary() and GetProcAddress() from Kernel32 to get the
addreses, but is there a way to actually call an API method by its
address from VB? Or can anyone suggest anything else?

TIA!

May 23 '06 #17
Anthony Jones wrote:
"mr_unreliable" wrote:

There are two pre-programmed, pre-digested solutions to this.


Both of these approaches have a serious draw back. They require that
a small piece of assembly be used to thunk the call. Problem is that
this little piece of assembly resides in memory allocated as data.
Back when these approaches were originally written that wasn't a
problem. Today though a machine running with DEP turned on will kill
any process trying to do this.


I usually hesitate to offer only a commercial solution, but all the others have been mentioned, and as you note they have drawbacks.

While it isn't free, our Stamina library has among its almost 500 assembly-language functions, DxCall and DxCallByName. These can call arbitrary stdcall, pascal and cdecl functions having up to 16 parameters (and a return value) of any mix of variant-safe types. It also deals with conversions between Unicode and Ansi as needed.

DxCall is best for repeated calls to the same function, or for calling VB functions (internal callbacks, for example) since it takes an address or function pointer. DxCallByName is simpler for one-off calls, since it takes a DLL name and function name as parameters and deals with LoadLibrary etc internally.

Stamina is for VB32 and VBA only, not .net

--

Jim Mack
MicroDexterity Inc
www.microdexterity.com
May 23 '06 #18
Right. But microsoft's advice in this situation is to
allocate memory with both data and execute privileges
turned on, and put your assembly in that.

Fortunately, this is not hard to do, and with that
modification Arkadiy Olovyannikov's code will work
successfully on xp -- even with dep turned on --
until microsoft comes up with some other hurdle
to jump over.

cheers, jw

Anthony Jones wrote:
Both of these approaches have a serious draw back. They require that a
small piece of assembly be used to thunk the call. Problem is that this
little piece of assembly resides in memory allocated as data. Back when
these approaches were originally written that wasn't a problem. Today
though a machine running with DEP turned on will kill any process trying to
do this.

May 23 '06 #19
Michael C wrote:
"Karl E. Peterson" <ka**@mvps.org> wrote in message
news:uZ**************@TK2MSFTNGP03.phx.gbl...
I don't see how matthew's method would be any less hacky. I can't
see it though as that page requires a login.


http://www.BugMeNot.com <- HTH!


Ok, I had a look at his code. It shoves assembly code into a currency
variable and does pretty much the same thing but requires the extra
complexity of creating and referencing a typelib (presumably a new
typelib for each different call signature). It also has the reduced
flexibility of not being able to call cdecl functions. Matt has a bad
habit of overcomplicating things. But then again karl, don't let
logic get in your way. :-)


You seem quite confused. But then again, what else is new?

I was only attempting to help you view what you saw to be off-limits.

No moral or technical judgements were offered.
--
Working without a .NET?
http://classicvb.org/
May 23 '06 #20
"Karl E. Peterson" <ka**@mvps.org> wrote in message
news:ut*************@TK2MSFTNGP02.phx.gbl...
You seem quite confused. But then again, what else is new?

I was only attempting to help you view what you saw to be off-limits.

No moral or technical judgements were offered.


Sorry karl, I didn't look at the link. Going by the sh1t you've been posting
lately I just assumed it was another one of your insults.

Michael
May 23 '06 #21
"mr_unreliable" <ki********************@notmail.com> wrote in message
news:ex**************@TK2MSFTNGP02.phx.gbl...
Right. But microsoft's advice in this situation is to
allocate memory with both data and execute privileges
turned on, and put your assembly in that.

Fortunately, this is not hard to do, and with that
modification Arkadiy Olovyannikov's code will work
successfully on xp -- even with dep turned on --
until microsoft comes up with some other hurdle
to jump over.


From memory I think Matt's code handled this issue.

Michael
May 23 '06 #22
Michael C wrote:
"Karl E. Peterson" <ka**@mvps.org> wrote in message
news:ut*************@TK2MSFTNGP02.phx.gbl...
You seem quite confused. But then again, what else is new?

I was only attempting to help you view what you saw to be off-limits.

No moral or technical judgements were offered.


Sorry karl, I didn't look at the link. Going by the sh1t you've been
posting lately I just assumed it was another one of your insults.


I see no need to be redundant. You "speak for" yourself quite clearly.
--
Working without a .NET?
http://classicvb.org/
May 23 '06 #23
On Mon, 22 May 2006 12:52:10 -0700, "Thorsten Albers"
<al******@MOVEuni-freiburg.de> wrote:
Usenet*User <**@*.**> schrieb im Beitrag
<ta********************************@4ax.com>...
I need to be able to call the same API function from VB, which will
reside in different DLLs. While all of the functions have the same
signature and name, DLL file names are not known at compile time.
Therefore, my assumption that using Declare statement or DllImport
attribute is NOT an option in such a case.

I can use LoadLibrary() and GetProcAddress() from Kernel32 to get the
addreses, but is there a way to actually call an API method by its
address from VB? Or can anyone suggest anything else?
I can think of two ways:

a) Build and use a standard DLL (C(++)) which redirects the function call
to the respective DLL.


That's what I ended up doing. So far so good.
b) Add a declare statement with a - more or less :-) - unique library file
name. Then, before calling the library function, make a copy of the
original library and name it with this unique file name. The copy of the
library of course has to be located somewhere where the OS can find it.


Was thinking of this, but decided no to pursue this path...

Thanks!
May 23 '06 #24
On 22 May 2006 13:30:39 -0700, "Chris Dunaway" <du******@gmail.com>
wrote:
Usenet User wrote:
I need to be able to call the same API function from VB, which will
reside in different DLLs. While all of the functions have the same
Why would you do this? Are you trying to create some sort of "plugin"
architecture? Do you have control over the .dll you are trying to call
or are they 3rd party?


Yes, we have a bunch of DLL from different vendors that implement the
same methods.
Perhaps you could create a single class in which you pass the name of
the .dll as a string and then inside the class, call the api method
based on that string.


Well, I am not quite sure what you have in mind. I would still need a
static Declare with the hardcoded DLL name. No?

Thanks!
May 23 '06 #25
On Tue, 23 May 2006 11:40:32 +1000, "Michael C" <no****@nospam.com>
wrote:
"Usenet User" < @ . > wrote in message
news:ta********************************@4ax.com.. .
I need to be able to call the same API function from VB, which will
reside in different DLLs. While all of the functions have the same
signature and name, DLL file names are not known at compile time.
Therefore, my assumption that using Declare statement or DllImport
attribute is NOT an option in such a case.

I can use LoadLibrary() and GetProcAddress() from Kernel32 to get the
addreses, but is there a way to actually call an API method by its
address from VB? Or can anyone suggest anything else?


If your dlls have the same name but diff dir just use LoadLibrary and
FreeLibrary with the standard vb6 declare, eg

Declare Function Whatever Lib "MyDLL" ....
Sub DoIt()
lib = LoadLibrary("C:\abc\MyDll.dll")
WhatEver(....)
FreeLibrary(lib)
End Sub

because a library of name MyDLL is already loaded vb6 will just use that.
Just make sure you match the no of loadlib calls with freelib and don't call
your function without calling LoadLibrary at least once somewhere in code.


Well, the names are different, unfortunately. Also, I'm talking about
VB.NET (i.e., read - CLR), not VB6.

Thank you!
May 23 '06 #26

"mr_unreliable" <ki********************@notmail.com> wrote in message
news:ex**************@TK2MSFTNGP02.phx.gbl...
Right. But microsoft's advice in this situation is to
allocate memory with both data and execute privileges
turned on, and put your assembly in that.

Where can I find this advice?
How is this done in VB6?
Fortunately, this is not hard to do, and with that
modification Arkadiy Olovyannikov's code will work
successfully on xp -- even with dep turned on --
until microsoft comes up with some other hurdle
to jump over.

Any chance of showing us how this is done?

cheers, jw

Anthony Jones wrote:
Both of these approaches have a serious draw back. They require that a
small piece of assembly be used to thunk the call. Problem is that this
little piece of assembly resides in memory allocated as data. Back when
these approaches were originally written that wasn't a problem. Today
though a machine running with DEP turned on will kill any process trying to do this.

May 23 '06 #27
"Usenet User" < @ . > wrote in message
news:7a********************************@4ax.com
Well, the names are different, unfortunately. Also, I'm talking about
VB.NET (i.e., read - CLR), not VB6.


Then you aren't talking about VB no matter how misleadingly MS has named
their product
--
try asking in a group with "dotnet" in the name; this group is for VB 6.0
and earlier
VB.Net is Not.VB

May 23 '06 #28

"Michael C" <no****@nospam.com> wrote in message
news:OF**************@TK2MSFTNGP05.phx.gbl...
"mr_unreliable" <ki********************@notmail.com> wrote in message
news:ex**************@TK2MSFTNGP02.phx.gbl...
Right. But microsoft's advice in this situation is to
allocate memory with both data and execute privileges
turned on, and put your assembly in that.

Fortunately, this is not hard to do, and with that
modification Arkadiy Olovyannikov's code will work
successfully on xp -- even with dep turned on --
until microsoft comes up with some other hurdle
to jump over.


From memory I think Matt's code handled this issue.


It does if you use the C++ VBoost helper DLL but doesn't if you want avoid
that and use the bas module instead. Problem with the VBoost DLL is that it
doesn't load in a COM+ environment. I was able to circument this issue by
using some loader code.

Sadly the loader code used CallFunction techniques which lands us right back
into DEP problems anyway.

May 23 '06 #29

"Anthony Jones" <An*@yadayadayada.com> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP02.phx.gbl...
Where can I find this advice?


http://msdn.microsoft.com/security/p.../exec_imp.aspx
Fortunately, this is not hard to do, and with that
modification Arkadiy Olovyannikov's code will work
successfully on xp -- even with dep turned on --
until microsoft comes up with some other hurdle
to jump over.

Any chance of showing us how this is done?


Ca. two years ago I've posted an appropriate example:
http://tinyurl.com/ryhlk

Olaf
May 23 '06 #30
Michael C wrote:
"Karl E. Peterson" <ka**@mvps.org> wrote in message
news:ut*************@TK2MSFTNGP02.phx.gbl...
You seem quite confused. But then again, what else is new?

I was only attempting to help you view what you saw to be off-limits.

No moral or technical judgements were offered.


Sorry karl, I didn't look at the link. Going by the sh1t you've been posting
lately I just assumed it was another one of your insults.


Best kettle pointer I've dereferenced all day. Nice job, pot.
May 23 '06 #31
"Bob O`Bob" <fi*******@yahoogroups.com> wrote in message news:e%
Best kettle pointer I've dereferenced all day. Nice job, pot.


Funny *you* should say that bob. Still think With is faster?

Michael
May 24 '06 #32
Usenet User,
In addition to all the other comments, you should be able to use LoadLibrary
& GetProcAddress. The "trick" is converting the IntPtr that GetProcAddress
returns to a Delegate.

Luckily In .NET 2.0 the System.Runtime.InterpoServices.Marshal class has a
GetDelegateForFunctionPointer method that will convert the IntPtr to a
Delegate.

http://msdn2.microsoft.com/en-us/lib...yh(vs.80).aspx

For an example of how to use the above see:
http://www.pinvoke.net/default.aspx/...ocAddress.html

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Usenet User" < @ . > wrote in message
news:ta********************************@4ax.com...
|I need to be able to call the same API function from VB, which will
| reside in different DLLs. While all of the functions have the same
| signature and name, DLL file names are not known at compile time.
| Therefore, my assumption that using Declare statement or DllImport
| attribute is NOT an option in such a case.
|
| I can use LoadLibrary() and GetProcAddress() from Kernel32 to get the
| addreses, but is there a way to actually call an API method by its
| address from VB? Or can anyone suggest anything else?
|
| TIA!
May 24 '06 #33

"Schmidt" <ss*@online.de> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...

"Anthony Jones" <An*@yadayadayada.com> schrieb im Newsbeitrag
news:%2****************@TK2MSFTNGP02.phx.gbl...
Where can I find this advice?

http://msdn.microsoft.com/security/p.../exec_imp.aspx
Fortunately, this is not hard to do, and with that
modification Arkadiy Olovyannikov's code will work
successfully on xp -- even with dep turned on --
until microsoft comes up with some other hurdle
to jump over.

Any chance of showing us how this is done?


Ca. two years ago I've posted an appropriate example:
http://tinyurl.com/ryhlk

Olaf

Nice one :)

May 24 '06 #34
On Tue, 23 May 2006 10:16:54 -0700, "Bob Butler" <ti*******@nospam.ever> wrote:

¤ "Usenet User" < @ . > wrote in message
¤ news:7a********************************@4ax.com
¤ > Well, the names are different, unfortunately. Also, I'm talking about
¤ > VB.NET (i.e., read - CLR), not VB6.
¤
¤ Then you aren't talking about VB no matter how misleadingly MS has named
¤ their product

It's certainly not VB 6.0, no, despite the fact that it still uses a version of the BASIC language.
Paul
~~~~
Microsoft MVP (Visual Basic)
May 25 '06 #35
On Tue, 23 May 2006 13:41:43 -0700, Bob O`Bob
<fi*******@yahoogroups.com> wrote:
Michael C wrote:
"Karl E. Peterson" <ka**@mvps.org> wrote in message
news:ut*************@TK2MSFTNGP02.phx.gbl...
You seem quite confused. But then again, what else is new?

I was only attempting to help you view what you saw to be off-limits.

No moral or technical judgements were offered.


Sorry karl, I didn't look at the link. Going by the sh1t you've been posting
lately I just assumed it was another one of your insults.


Best kettle pointer I've dereferenced all day. Nice job, pot.


HAHAHAHAHAHAHAhahahaha<snort> hahah ha ha ha <cough>

Do you mind if I use that as a sig ?
May 26 '06 #36
On Wed, 24 May 2006 11:20:47 +1000, "Michael C" <no****@nospam.com>
wrote:
"Bob O`Bob" <fi*******@yahoogroups.com> wrote in message news:e%
Best kettle pointer I've dereferenced all day. Nice job, pot.


Funny *you* should say that bob. Still think With is faster?

Michael


He would not be alone.
Letting VB have to follow a long list of
"Thing.anotherThing.yetAnotherThing." waste time cycles that can be
replaced with one With./ end With.

Besides, it does make for clearer code, no ?

May 26 '06 #37
On Fri, 26 May 2006 17:29:43 GMT, ri******@sympatico.ca (bitshifter)
wrote:
in <44***************@news1.qc.sympatico.ca>
On Tue, 23 May 2006 13:41:43 -0700, Bob O`Bob
<fi*******@yahoogroups.com> wrote:
Michael C wrote:
"Karl E. Peterson" <ka**@mvps.org> wrote in message
news:ut*************@TK2MSFTNGP02.phx.gbl...
You seem quite confused. But then again, what else is new?

I was only attempting to help you view what you saw to be off-limits.

No moral or technical judgements were offered.

Sorry karl, I didn't look at the link. Going by the sh1t you've been posting
lately I just assumed it was another one of your insults.


Best kettle pointer I've dereferenced all day. Nice job, pot.


HAHAHAHAHAHAHAhahahaha<snort> hahah ha ha ha <cough>

Do you mind if I use that as a sig ?


I thought it was really clever too. :-)

---

Stefan Berglund
May 26 '06 #38
Stefan Berglund wrote:
On Fri, 26 May 2006 17:29:43 GMT, ri******@sympatico.ca (bitshifter)
wrote:
in <44***************@news1.qc.sympatico.ca>
On Tue, 23 May 2006 13:41:43 -0700, Bob O`Bob

Best kettle pointer I've dereferenced all day. Nice job, pot.

HAHAHAHAHAHAHAhahahaha<snort> hahah ha ha ha <cough>

Do you mind if I use that as a sig ?


I thought it was really clever too. :-)

Feel free.
May 26 '06 #39
"bitshifter" <ri******@sympatico.ca> wrote in message
news:44***************@news1.qc.sympatico.ca...
He would not be alone.
Letting VB have to follow a long list of
"Thing.anotherThing.yetAnotherThing." waste time cycles that can be
replaced with one With./ end With.
Here we go again :-) This is a myth. With is *not* faster. This has been
discussed at length here and many tried to prove me wrong but no one could.
Bob in particular tried very hard but once he realised I was correct went
very quiet. Try this code: http://mikesdriveway.com/misc/with.zip
Besides, it does make for clearer code, no ?


No, it's ugly imo. In very rare cases it could be ok, eg:

With A.B.C.D.MyControl
.Width = 100
.Height = 100
.Text = "ABC"
etc
End with

but what happens when you need to add some code to calculate width, height
and text, do you delete the with block or just stick this code inside it?

Michael
May 27 '06 #40
Liz

"bitshifter" <ri******@sympatico.ca> wrote in message
news:44***************@news1.qc.sympatico.ca...
He would not be alone.
Letting VB have to follow a long list of
"Thing.anotherThing.yetAnotherThing." waste time cycles that can be
replaced with one With./ end With.


you're thinking like a typist and not like a compiler
May 27 '06 #41
Liz wrote:
"bitshifter" <ri******@sympatico.ca> wrote in message
news:44***************@news1.qc.sympatico.ca...
He would not be alone.
Letting VB have to follow a long list of
"Thing.anotherThing.yetAnotherThing." waste time cycles that can be
replaced with one With./ end With.


you're thinking like a typist and not like a compiler

You're over-thinking what a compiler can /safely/ do.

Bob
May 27 '06 #42
Liz

"Bob O`Bob" <fi*******@yahoogroups.com> wrote in message
news:uT**************@TK2MSFTNGP05.phx.gbl...
He would not be alone.
Letting VB have to follow a long list of
"Thing.anotherThing.yetAnotherThing." waste time cycles that can be
replaced with one With./ end With.
you're thinking like a typist and not like a compiler

You're over-thinking what a compiler can /safely/ do.


How so, Bob? I didn't say a thing about what a compiler can do, safely or
otherwise. My comment was about what a compiler CAN'T do, namely, save you
clock cycles when you use a WITH ... END WITH construct. Some may like the
convenience of saving a few keystrokes but it has no impact at all on
efficiency of the machine code emitted.

L

May 28 '06 #43
Liz wrote:
"Bob O`Bob" wrote...
He would not be alone.
Letting VB have to follow a long list of
"Thing.anotherThing.yetAnotherThing." waste time cycles that can be
replaced with one With./ end With.

you're thinking like a typist and not like a compiler

You're over-thinking what a compiler can /safely/ do.


How so, Bob? I didn't say a thing about what a compiler can do,
safely or otherwise. My comment was about what a compiler CAN'T do,
namely, save you clock cycles when you use a WITH ... END WITH
construct. Some may like the convenience of saving a few keystrokes
but it has no impact at all on efficiency of the machine code emitted.


Oh, dear -- not this again. There should never be threads that cross ..NET <-> .NOT boundaries because there's no telling where you're coming from.

Bob is coming from VB6, where With...End can definitely save cycles over naively accessing properties one at a time. It does this by holding a temporary reference to an object in memory. Maybe the compiler could do the work, but it doesn't. You could also create a temporary object yourself, but why bother when you have this handy construct?

In VB6,

With MyObject.Yardarm
.Farkle = 54
.Singed = True
.Unhatting = Argyle
.Rey = Tal
End With

....is measurably faster than:

MyObject.Yardarm.Farkle = 54
MyObject.Yardarm.Singed = True
MyObject.Yardarm.Unhatting = Argyle
MyObject.Yardarm.Rey = Tal

I have no idea what the situation in .NET is.

--

Jim Mack
MicroDexterity Inc
www.microdexterity.com
May 28 '06 #44
"Jim Mack" <jm***@mdxi.nospam.com> wrote in message
news:OG**************@TK2MSFTNGP03.phx.gbl...
With MyObject.Yardarm
.Farkle = 54
.Singed = True
.Unhatting = Argyle
.Rey = Tal
End With

...is measurably faster than:

MyObject.Yardarm.Farkle = 54
MyObject.Yardarm.Singed = True
MyObject.Yardarm.Unhatting = Argyle
MyObject.Yardarm.Rey = Tal


But With it is measurably slower than creating an object variable.

Michael
May 28 '06 #45
It is?
"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:84********************************@4ax.com...
On Tue, 23 May 2006 10:16:54 -0700, "Bob Butler" <ti*******@nospam.ever>
wrote:

¤ "Usenet User" < @ . > wrote in message
¤ news:7a********************************@4ax.com
¤ > Well, the names are different, unfortunately. Also, I'm talking about
¤ > VB.NET (i.e., read - CLR), not VB6.
¤
¤ Then you aren't talking about VB no matter how misleadingly MS has named
¤ their product

It's certainly not VB 6.0, no, despite the fact that it still uses a
version of the BASIC language.


It does? I thought it just used some of the same keywords as BASIC.

Ok, I suppose, like Java is a 'version of C'

May 29 '06 #46
On Mon, 29 May 2006 19:25:04 +1000, "david epsom dot com dot au" <david@epsomdotcomdotau> wrote:

¤ >
¤ > It's certainly not VB 6.0, no, despite the fact that it still uses a
¤ > version of the BASIC language.
¤
¤ It does? I thought it just used some of the same keywords as BASIC.
¤

Uses most of them from my experience.

¤ Ok, I suppose, like Java is a 'version of C'

You're asking the wrong person. ;-)
Paul
~~~~
Microsoft MVP (Visual Basic)
May 30 '06 #47

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

Similar topics

5
by: Alex Lyman | last post by:
Does anyone have any code handy (or know what a good direction for me to head in), to call functions, if you have an address of the function, its declspec (for my app, it's limited to _stdcall and...
3
by: Clausmeyer | last post by:
I want to execute a dynamically generated sql-statement from inside an user-defined-function. Calling functions and extended stored-procs is allowed so I tried sp_executesql as well as...
7
by: Julia Briggs | last post by:
Hello World - I admit I'm new to javascript but I've tried for days to find a solution to my problem. Basically I have 3 unique javascript files that do different screen display events that I...
2
by: Joe | last post by:
I have 3 functions: ClientInfoA is doing something ClientInfoB is doing something SelectFunction2Run is a function to determine which function needed to run based on the value of the variable...
5
by: Francesco Bochicchio | last post by:
Hi all, anybody knows if there is a (standard, portable) way to dinamically build a list of parameters to call a C function? Something like va_start & co, but to be used on the calling side? ...
1
by: Peter Rilling | last post by:
I have the following nAnt task which does not work. The problem is that I an calling is-assembly(...) passing in as a parameter a dynamically property. This property is not known until runtime. ...
2
by: Chris Mellon | last post by:
>>def test_func(): .... pass .... <function test_func2 at 0x01B8C2F0> <function test_func at 0x01B8C270> Why almost twice the calling overhead for a dynamic function?
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
7
by: mirandacascade | last post by:
Note: I'm not sure if the subject line of this post uses the correct terminology, so apologies if the subject line turns out to be misleading. I think it's probably easier to provide a trivial...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.