|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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! Usenet User < @ . > schrieb im Beitrag
<tau372d0grgrb2mhhdo6g00upj34b5m***@4ax.com>... > I need to be able to call the same API function from VB, which will I can think of two ways:> 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? 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 ---------------------------------------------------------------------- On Mon, 22 May 2006 12:52:10 -0700, "Thorsten Albers"
<alber***@MOVEuni-freiburg.de> wrote: Show quoteHide quote >Usenet User < @ . > schrieb im Beitrag That's what I ended up doing. So far so good.><tau372d0grgrb2mhhdo6g00upj34b5m***@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 Was thinking of this, but decided no to pursue this path...>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. Thanks! Usenet User wrote:
> I need to be able to call the same API function from VB, which will Why would you do this? Are you trying to create some sort of "plugin"> reside in different DLLs. While all of the functions have the same 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 <aaron.ke***@gmail.com> wrote in message
news:1148332371.274366.192150@i39g2000cwa.googlegroups.com... No> cant you just use > CallByName "Msgbox('Hello World')" Show quoteHide quote > On 22 May 2006 13:30:39 -0700, "Chris Dunaway" <dunaw***@gmail.com> Yes, we have a bunch of DLL from different vendors that implement thewrote: >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? > same methods. >Perhaps you could create a single class in which you pass the name of Well, I am not quite sure what you have in mind. I would still need a>the .dll as a string and then inside the class, call the api method >based on that string. static Declare with the hardcoded DLL name. No? Thanks! 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 Another way (hack) is to use the function address obtained with>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? 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) 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/listissue.asp?pubID=1&MagIssueId=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: Show quoteHide quote > 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! Matt's book still appears to be available through
http://service.bfast.com/bfast/click?bfmid=2181&sourceid=251059&bfpid=0201707128&bfmtype=book -- Randy Birch MS MVP Visual Basic http://vbnet.mvps.org/ Please reply to the newsgroups so all can participate. "mr_unreliable" <kindlyReplyToNewsgr***@notmail.com> wrote in message There are two pre-programmed, pre-digested solutions to this.news:%23yL9SPffGHA.764@TK2MSFTNGP03.phx.gbl... hi Usenet, 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/listissue.asp?pubID=1&MagIssueId=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: Show quoteHide quote > 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! > Matt's book still appears to be available through It's a little bit cheaper here...> http://service.bfast.com/bfast/click?bfmid=2181&sourceid=251059&bfpid=0201707128&bfmtype=book http://www.amazon.com/gp/product/0201707128/sr=8-1/qid=1148342855/ref=pd_bbs_1/002-1414359-6396001?%5Fencoding=UTF8 Rick "mr_unreliable" <kindlyReplyToNewsgr***@notmail.com> wrote in message I downloaded this code and much to my suprise it was a modification to some news:%23yL9SPffGHA.764@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 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 I don't see how matthew's method would be any less hacky. I can't see it > 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". though as that page requires a login. Michael Michael C wrote:
>> 2. However, the api newsgroupies here may be expected to heap http://www.BugMeNot.com <- HTH!>> 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. "Karl E. Peterson" <k***@mvps.org> wrote in message Considering what I have seen of matt's I'd imagine it would be significantly news:uZz6xngfGHA.1520@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! more hacky. Michael "Karl E. Peterson" <k***@mvps.org> wrote in message Ok, I had a look at his code. It shoves assembly code into a currency news:uZz6xngfGHA.1520@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! 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 On Tue, 23 May 2006 12:17:36 +1000, "Michael C" <nospam@nospam.com> in <OHP2U7gfGHA.5***@TK2MSFTNGP02.phx.gbl> wrote: Show quoteHide quote >"Karl E. Peterson" <k***@mvps.org> wrote in message You must be one of those irreverent dot net freaks that think you can>news:uZz6xngfGHA.1520@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 > 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 "Stefan Berglund" <sorry.no.kool***@for.me> wrote in message What on earth are you talking about. I did not mention dot net at all in news:dd0572h6orcn10d88r1i6647l3clbtrhbf@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. 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 Michael C wrote:
Show quoteHide quote > "Karl E. Peterson" <k***@mvps.org> wrote in message You seem quite confused. But then again, what else is new?> news:uZz6xngfGHA.1520@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. :-) I was only attempting to help you view what you saw to be off-limits. No moral or technical judgements were offered. "Karl E. Peterson" <k***@mvps.org> wrote in message Sorry karl, I didn't look at the link. Going by the sh1t you've been posting news:utU1hFofGHA.356@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. lately I just assumed it was another one of your insults. Michael Michael C wrote:
> "Karl E. Peterson" <k***@mvps.org> wrote in message I see no need to be redundant. You "speak for" yourself quite clearly.> news:utU1hFofGHA.356@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 C wrote:
> "Karl E. Peterson" <k***@mvps.org> wrote in message Best kettle pointer I've dereferenced all day. Nice job, pot.> news:utU1hFofGHA.356@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. "Bob O`Bob" <filter***@yahoogroups.com> wrote in message news:e% Funny *you* should say that bob. Still think With is faster?> Best kettle pointer I've dereferenced all day. Nice job, pot. Michael On Wed, 24 May 2006 11:20:47 +1000, "Michael C" <nospam@nospam.com> He would not be alone.wrote: >"Bob O`Bob" <filter***@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 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 ? "bitshifter" <richm***@sympatico.ca> wrote in message Here we go again :-) This is a myth. With is *not* faster. This has been news:44773b15.17047109@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. 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 "bitshifter" <richm***@sympatico.ca> wrote in message you're thinking like a typist and not like a compilernews:44773b15.17047109@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. Liz wrote:
> "bitshifter" <richm***@sympatico.ca> wrote in message You're over-thinking what a compiler can /safely/ do.> news:44773b15.17047109@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 > > Bob "Bob O`Bob" <filter***@yahoogroups.com> wrote in message How so, Bob? I didn't say a thing about what a compiler can do, safely or news:uTtZn0cgGHA.4864@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. 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 Liz wrote:
Show quoteHide quote > "Bob O`Bob" wrote... 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. > >>>> 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. > 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.
Show quote
Hide quote
"Jim Mack" <jmack@mdxi.nospam.com> wrote in message But With it is measurably slower than creating an object variable.news:OGnjv5jgGHA.4276@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 Michael On Tue, 23 May 2006 13:41:43 -0700, Bob O`Bob
<filter***@yahoogroups.com> wrote: Show quoteHide quote >Michael C wrote: HAHAHAHAHAHAHAhahahaha<snort> hahah ha ha ha <cough>>> "Karl E. Peterson" <k***@mvps.org> wrote in message >> news:utU1hFofGHA.356@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. Do you mind if I use that as a sig ? On Fri, 26 May 2006 17:29:43 GMT, richm***@sympatico.ca (bitshifter)
wrote: in <44773ad9.16986***@news1.qc.sympatico.ca> Show quoteHide quote >On Tue, 23 May 2006 13:41:43 -0700, Bob O`Bob I thought it was really clever too. :-)><filter***@yahoogroups.com> wrote: > >>Michael C wrote: >>> "Karl E. Peterson" <k***@mvps.org> wrote in message >>> news:utU1hFofGHA.356@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 ? > --- Stefan Berglund Stefan Berglund wrote:
Show quoteHide quote > On Fri, 26 May 2006 17:29:43 GMT, richm***@sympatico.ca (bitshifter) Feel free.> wrote: > in <44773ad9.16986***@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. :-)
Show quote
Hide quote
"mr_unreliable" <kindlyReplyToNewsgr***@notmail.com> wrote in message Both of these approaches have a serious draw back. They require that anews:%23yL9SPffGHA.764@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/listissue.asp?pubID=1&MagIssueId=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. > 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. Show quoteHide quote > 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! Anthony Jones wrote:
> "mr_unreliable" wrote: I usually hesitate to offer only a commercial solution, but all the others have been mentioned, and as you note they have drawbacks.>> >> 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. 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 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: Show quoteHide quote > 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. "mr_unreliable" <kindlyReplyToNewsgr***@notmail.com> wrote in message From memory I think Matt's code handled this issue.news:exRaSEofGHA.3588@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. Michael
Show quote
Hide quote
"Michael C" <nospam@nospam.com> wrote in message It does if you use the C++ VBoost helper DLL but doesn't if you want avoidnews:OFo$PKofGHA.4940@TK2MSFTNGP05.phx.gbl... > "mr_unreliable" <kindlyReplyToNewsgr***@notmail.com> wrote in message > news:exRaSEofGHA.3588@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. > 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. "mr_unreliable" <kindlyReplyToNewsgr***@notmail.com> wrote in message Where can I find this advice?news:exRaSEofGHA.3588@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. > How is this done in VB6? > Fortunately, this is not hard to do, and with that Any chance of showing us how this is done?> 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. > Show quoteHide quote > 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. "Anthony Jones" <A**@yadayadayada.com> schrieb im Newsbeitrag
http://msdn.microsoft.com/security/productinfo/XPSP2/memoryprotection/exec_imp.aspx
news:%23Lh0TyofGHA.2068@TK2MSFTNGP02.phx.gbl... > Where can I find this advice? > > Fortunately, this is not hard to do, and with that Ca. two years ago I've posted an appropriate example:> > 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? http://tinyurl.com/ryhlk Olaf "Schmidt" <s**@online.de> wrote in message
http://msdn.microsoft.com/security/productinfo/XPSP2/memoryprotection/exec_imp.aspx
news:%23rZT0cqfGHA.4172@TK2MSFTNGP04.phx.gbl... > > "Anthony Jones" <A**@yadayadayada.com> schrieb im Newsbeitrag > news:%23Lh0TyofGHA.2068@TK2MSFTNGP02.phx.gbl... > > > Where can I find this advice? > > > Nice one :)> > > 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 "Usenet User" < @ . > wrote in message If your dlls have the same name but diff dir just use LoadLibrary and news:tau372d0grgrb2mhhdo6g00upj34b5mv32@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? 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
Show quote
Hide quote
On Tue, 23 May 2006 11:40:32 +1000, "Michael C" <nospam@nospam.com> Well, the names are different, unfortunately. Also, I'm talking aboutwrote: >"Usenet User" < @ . > wrote in message >news:tau372d0grgrb2mhhdo6g00upj34b5mv32@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. VB.NET (i.e., read - CLR), not VB6. Thank you! "Usenet User" < @ . > wrote in message Then you aren't talking about VB no matter how misleadingly MS has namednews:7ag672ljdbjkd6pl9iip3kq8gi11qjc641@4ax.com > Well, the names are different, unfortunately. Also, I'm talking about > VB.NET (i.e., read - CLR), not VB6. 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 On Tue, 23 May 2006 10:16:54 -0700, "Bob Butler" <tiredofit@nospam.ever> wrote: ¤ > Well, the names are different, unfortunately. Also, I'm talking about¤ "Usenet User" < @ . > wrote in message ¤ news:7ag672ljdbjkd6pl9iip3kq8gi11qjc641@4ax.com ¤ > 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) It is?
Show quoteHide quote "Paul Clement" <UseAdddressAtEndofMess***@swspectrum.com> wrote in message It does? I thought it just used some of the same keywords as BASIC.news:84bb721vd0uul50bp3e4ro5v364mncvohg@4ax.com... > On Tue, 23 May 2006 10:16:54 -0700, "Bob Butler" <tiredofit@nospam.ever> > wrote: > > ¤ "Usenet User" < @ . > wrote in message > ¤ news:7ag672ljdbjkd6pl9iip3kq8gi11qjc641@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. Ok, I suppose, like Java is a 'version of C' 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) 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/library/zdx6dyyh(vs.80).aspx For an example of how to use the above see: http://www.pinvoke.net/default.aspx/kernel32/GetProcAddress.html -- Show quoteHide quoteHope 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:tau372d0grgrb2mhhdo6g00upj34b5mv32@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!
arrghh dot vs comma
How to have a clean exit Thread takes up 100% CPU Word automation version problem. Setting tab stops in RTF control Caret Hiding SortCompare of DataGridView - how to? Help: Control loops & properties in VB .Net 2005 Query based of a value in a combo box Translation to vb from C# ? |
|||||||||||||||||||||||