|
| Author |
Message |
Paul Coene
Joined: 20 Feb 2008 Posts: 3
|
Posted: Wed Feb 20, 2008 5:17 pm Post subject: GetProcAddress not working in VB6 for me, Ideas? Full progr |
|
|
I can't get GetProcAddress to return anything but 0. The LoadLibrary
seems to work.
Full console app below:
---------------------------------------------------------------
Module Module1
Private Declare Auto Function LoadLibrary Lib "kernel32.dll" (ByVal ProcName As String) As Integer
Private Declare Auto Function GetProcAddress Lib "kernel32.dll" (ByVal ModuleHandle As Integer, ByVal ProcName As String) As Integer
Sub Main()
Dim ModuleHandle As Integer
Dim MethodPointer As Integer
ModuleHandle = LoadLibrary("kernel32")
If ModuleHandle = 0 Then
Console.WriteLine("Cannot open kernel32")
Else
Console.WriteLine("kernel32 opened")
End If
MethodPointer = GetProcAddress(ModuleHandle, "LoadLibrary")
If MethodPointer = 0 Then
Console.WriteLine("Cannot find proc LoadLibrary")
Else
Console.WriteLine("Found LoadLibrary")
End If
Console.ReadLine()
End Sub
End Module
---------------------------------------------------------------
Results:
kernel32 opened
Cannot find proc LoadLibrary
Why?
--
It's 3:30, why aren't you at work?
I.. I didn't feel like it.
Archived from group: microsoft>public>vb>winapi |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Wed Feb 20, 2008 3:25 pm Post subject: Re: GetProcAddress not working in VB6 for me, Ideas? Full p |
|
|
Paul Coene wrote:
>I can't get GetProcAddress to return anything but 0.
You'd have better hope for finding a solution here if you upgraded to VB6.
--
..NET: It's About Trust!
http://vfred.mvps.org |
|
| Back to top |
|
 |
Paul Coene
Joined: 20 Feb 2008 Posts: 3
|
Posted: Wed Feb 20, 2008 5:32 pm Post subject: Re: GetProcAddress not working in VB6 for me, Ideas? Full p |
|
|
On Wed, 20 Feb 2008 10:25:05 -0800, Karl E. Peterson wrote:
> Paul Coene wrote:
>>I can't get GetProcAddress to return anything but 0.
>
> You'd have better hope for finding a solution here if you upgraded to VB6.
I'm using VS 2005 .NET. Isn't that like VB8? I'm new to the
windows development world - well sort of. Did I mislead?
--
It's 3:30, why aren't you at work?
I.. I didn't feel like it. |
|
| Back to top |
|
 |
Thorsten Albers
Joined: 04 Oct 2007 Posts: 756
|
Posted: Wed Feb 20, 2008 3:39 pm Post subject: Re: GetProcAddress not working in VB6 for me, Ideas? Full p |
|
|
Paul Coene schrieb im Beitrag
...
> I can't get GetProcAddress to return anything but 0. The LoadLibrary
> seems to work.
> ---------------------------------------------------------------
> Module Module1
> Private Declare Auto Function LoadLibrary Lib "kernel32.dll" (ByVal
ProcName As String) As Integer
> Private Declare Auto Function GetProcAddress Lib "kernel32.dll"
(ByVal ModuleHandle As Integer, ByVal ProcName As String) As Integer
>
> Sub Main()
> Dim ModuleHandle As Integer
> Dim MethodPointer As Integer
a) Your code isn't VB 'classic' code! This newsgroup is for VB <= 6.0 aka
'classic' only!
b) C/C++ 'int' is a 4 byte data type. VB 'Integer' is a 2 byte data type.
For C/C++ 'int' you have to use 'Long' in VB.
--
----------------------------------------------------------------------
THORSTEN ALBERS Universität Freiburg
albers@
uni-freiburg.de
---------------------------------------------------------------------- |
|
| Back to top |
|
 |
Karl E. Peterson
Joined: 04 Oct 2007 Posts: 4836
|
Posted: Wed Feb 20, 2008 3:46 pm Post subject: Re: GetProcAddress not working in VB6 for me, Ideas? Full p |
|
|
Paul Coene wrote:
> On Wed, 20 Feb 2008 10:25:05 -0800, Karl E. Peterson wrote:
>
>> Paul Coene wrote:
>>>I can't get GetProcAddress to return anything but 0.
>>
>> You'd have better hope for finding a solution here if you upgraded to VB6.
>
> I'm using VS 2005 .NET. Isn't that like VB8? I'm new to the
> windows development world - well sort of. Did I mislead?
No, you were misled by evil marketeers. It's "like" VB in name only. Otherwise,
the two share almost nothing in common, most especially source code! You're using
the bastardized version. Would suggest you find a group with ".dotnet." in its
name. Sorry...
--
..NET: It's About Trust!
http://vfred.mvps.org |
|
| Back to top |
|
 |
Scott Seligman
Joined: 04 Oct 2007 Posts: 12
|
Posted: Wed Feb 20, 2008 4:00 pm Post subject: Re: GetProcAddress not working in VB6 for me, Ideas? Full p |
|
|
Paul Coene wrote:
>
>I can't get GetProcAddress to return anything but 0. The LoadLibrary
>seems to work.
As others have pointed out, this newsgroup isn't appropriate for
managed code questions. Nevertheless, I'll take a stab at answering
it:
>Private Declare Auto Function GetProcAddress Lib "kernel32.dll" (ByVal
>PrModuleHandle As Integer, ByVal ocName As String) As Integer
You need to use "Ansi" instead of "Auto" here, since GetProcAddress
expects an ANSI string.
> MethodPointer = GetProcAddress(ModuleHandle, "LoadLibrary")
There is no function exported from kernel32.dll called "LoadLibrary".
Perhaps you meant "LoadLibraryW"?
--
--------- Scott Seligman and michelle dot net> ---------
The American Republic will endure, until politicians realize they can
bribe the people with their own money.
-- Alexis de Tocqueville |
|
| Back to top |
|
 |
Bob Butler
Joined: 04 Oct 2007 Posts: 1081
|
Posted: Wed Feb 20, 2008 4:23 pm Post subject: Re: GetProcAddress not working in VB6 for me, Ideas? Full p |
|
|
"Thorsten Albers" wrote in message $ba7ea8a0$9f01a8c0@xyz...
> Paul Coene schrieb im Beitrag
> ...
>> I can't get GetProcAddress to return anything but 0. The LoadLibrary
>> seems to work.
>> ---------------------------------------------------------------
>> Module Module1
>> Private Declare Auto Function LoadLibrary Lib "kernel32.dll" (ByVal
> ProcName As String) As Integer
>> Private Declare Auto Function GetProcAddress Lib "kernel32.dll"
> (ByVal ModuleHandle As Integer, ByVal ProcName As String) As Integer
>>
>> Sub Main()
>> Dim ModuleHandle As Integer
>> Dim MethodPointer As Integer
>
> a) Your code isn't VB 'classic' code! This newsgroup is for VB <= 6.0 aka
> 'classic' only!
>
> b) C/C++ 'int' is a 4 byte data type. VB 'Integer' is a 2 byte data type.
> For C/C++ 'int' you have to use 'Long' in VB.
But B# 'Integer' is 4 bytes... just one of the many gratuitous changes |
|
| Back to top |
|
 |
Paul Coene
Joined: 20 Feb 2008 Posts: 3
|
Posted: Wed Feb 20, 2008 6:39 pm Post subject: Re: GetProcAddress not working in VB6 for me, Ideas? Full p |
|
|
On Wed, 20 Feb 2008 11:00:32 -0800, Scott Seligman wrote:
> Paul Coene wrote:
>>
>>I can't get GetProcAddress to return anything but 0. The LoadLibrary
>>seems to work.
>
> As others have pointed out, this newsgroup isn't appropriate for
> managed code questions. Nevertheless, I'll take a stab at answering
> it:
>
>>Private Declare Auto Function GetProcAddress Lib "kernel32.dll" (ByVal
>>PrModuleHandle As Integer, ByVal ocName As String) As Integer
>
> You need to use "Ansi" instead of "Auto" here, since GetProcAddress
> expects an ANSI string.
That was the ticket.
I didn't see any newsgroups with .NET and VB in the name on our
distribution. Anyone have the names?
Thank you and sorry for the inappropriate post for this group. |
|
| Back to top |
|
 |
Thorsten Albers
Joined: 04 Oct 2007 Posts: 756
|
Posted: Wed Feb 20, 2008 6:21 pm Post subject: Re: GetProcAddress not working in VB6 for me, Ideas? Full p |
|
|
Bob Butler schrieb im Beitrag
...
> But B# 'Integer' is 4 bytes... just one of the many gratuitous changes
I didn't talk of B#.
--
----------------------------------------------------------------------
THORSTEN ALBERS Universität Freiburg
albers@
uni-freiburg.de
---------------------------------------------------------------------- |
|
| Back to top |
|
 |
Dave O.
Joined: 04 Oct 2007 Posts: 580
|
Posted: Thu Feb 21, 2008 4:05 pm Post subject: Re: GetProcAddress not working in VB6 for me, Ideas? Full p |
|
|
"Paul Coene" wrote in message @bellsouth.net...
> I didn't see any newsgroups with .NET and VB in the name on our
> distribution. Anyone have the names?
microsoft.public.dotnet.languages.vb
microsoft.public.dotnet.languages.vb.upgrade
microsoft.public.dotnet.languages.vb.controls
microsoft.public.dotnet.languages.vb.data
microsoft.public.dotnet.general
microsoft.public.vsnet.general
Regards
Dave O.
|
|
| Back to top |
|
 |
|