Pointer to String in VB2005

G

Guest

I'm trying to load this structure for a call to DeviceIoControl:

typedef struct _NDISUIO_QUERY_OID {
NDIS_OID Oid;
PTCHAR ptcDeviceName;
UCHAR Data[sizeof(ULONG)];
} NDISUIO_QUERY_OID, *PNDISUIO_QUERY_OID;

I created the equivalent in VB:

<StructLayout(LayoutKind.Sequential)> _
Public Class NDISUIO_QUERY_OID ' nuiouser.h
Public Oid As Int32
Public ptcDeviceName As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=4)> _
Public Data As String
End Class

What I need to proceed is: How do I get the pointer to my DeviceName string
to plug into ptcDeviceName? If it was C, I could just do ptcDeviceName =
&DeviceName -- I don't know how to do this in VB.

Thanks for any help,
Steve
 
G

Guest

Strings are already reference types so send it as a string.

Also, don't crosspost to so many groups.

And lastly, a Google search would probably have led you to a working
implementation - you're far from teh first to be using NDIS from amanaged
code. The OpenNETCF SDF has all of this stuff fully done and tested for
example.
 
G

Guest

Strings are already reference types so send it as a string.

I don't understand this -- are you saying my VB structure/class shouldn't
define ptcDeviceName as an IntPtr? If the structure's correct, how do I load
ptcDeviceName; i.e., get a String into a IntPtr?
Also, don't crosspost to so many groups.

Not sure what the issue is here. I posted to the NETCF/PPC groups because
I'm working on that platform, and posted to 3 other general VB groups because
they're specific to VB, and it seems a lot of the NETCF/PPC people use C# or
C++.
And lastly, a Google search would probably have led you to a working
implementation - you're far from teh first to be using NDIS from amanaged
code. The OpenNETCF SDF has all of this stuff fully done and tested for
example.

I could find NOTHING in VB -- I did a TON of Google searches before I posted
this message. Everything I've found is in C# or C++.

The specific question is: How do I get a pointer to a string in VB. Or am I
setting up the structure incorrectly?

I've used the OpenNETCF 1.4 source to get some ideas -- even though wading
through such a large code base (and it's C# not VB, so it doesn't answer my
specific question) takes a huge chunk of time, as it would with any large
system like it.
--
Chris Tacke - Embedded MVP
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--



mobilemobile said:
I'm trying to load this structure for a call to DeviceIoControl:

typedef struct _NDISUIO_QUERY_OID {
NDIS_OID Oid;
PTCHAR ptcDeviceName;
UCHAR Data[sizeof(ULONG)];
} NDISUIO_QUERY_OID, *PNDISUIO_QUERY_OID;

I created the equivalent in VB:

<StructLayout(LayoutKind.Sequential)> _
Public Class NDISUIO_QUERY_OID ' nuiouser.h
Public Oid As Int32
Public ptcDeviceName As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=4)> _
Public Data As String
End Class

What I need to proceed is: How do I get the pointer to my DeviceName
string
to plug into ptcDeviceName? If it was C, I could just do ptcDeviceName =
&DeviceName -- I don't know how to do this in VB.

Thanks for any help,
Steve
 
A

Armin Zingler

mobilemobile said:
The specific question is: How do I get a pointer to a string in VB.
Or am I setting up the structure incorrectly?

Strings are reference type, thus a String within a structure is a pointer:

Public ptcDeviceName As String

Maybe you need an additional MarshalAs attribute.


Armin
 
K

Ken Halter

All groups on the MS server that start with 'microsoft.public.vb' are there
to support VB Classic (v1 thru 6), so, this question is basically white
noise in non-dotnet groups.
 
K

Karl E. Peterson

mobilemobile said:
I created the equivalent in VB:

No, you created it in VB.NET, according to your Subject and source.

Keep this *crap* out of the ClassicVB groups!

It has no place here.

Please.
 
H

Herfried K. Wagner [MVP]

mobilemobile said:
I'm trying to load this structure for a call to DeviceIoControl:

typedef struct _NDISUIO_QUERY_OID {
NDIS_OID Oid;
PTCHAR ptcDeviceName;
UCHAR Data[sizeof(ULONG)];
} NDISUIO_QUERY_OID, *PNDISUIO_QUERY_OID;

I created the equivalent in VB:

<StructLayout(LayoutKind.Sequential)> _
Public Class NDISUIO_QUERY_OID ' nuiouser.h
Public Oid As Int32
Public ptcDeviceName As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=4)> _
Public Data As String
End Class

What I need to proceed is: How do I get the pointer to my DeviceName
string
to plug into ptcDeviceName? If it was C, I could just do ptcDeviceName =
&DeviceName -- I don't know how to do this in VB.

Declare the member simply 'As String'. In addition, set the structure's
character set ('CharSet' in 'StructLayout') to 'Auto').
 
G

Guest

Another poster in the classic VB groups gave me the info that all groups
starting with 'microsoft.public.vb' were classic VB only groups, which I
didn't know. I apologized to him. I will not, however, extend that courtesy
to you, given your overly emotional response.

I've programmed since the early 70s, Fortran IV, Dartmouth Basic, Algol,
Pascal, COBOL, C, right through creating large systems in VB5/6 (some of
which are still used) and now .NET.

If you choose to continue to use VB6, an environment which I loved working
in, and still have a large code base of, then that's a choice that works for
you. But calling the work of others "crap" is not a professional or reasoned
position. Every language has it's good sides and bad sides.
 
R

RobinS

I removed all of the groups from this posting except this one.

mobilemobile, many of the VB6 programmers seem to be bitter. Every time
..Net comes up in one of those newsgroups, there are a handful of people who
diss it, even though they have never tried it.

I'm impressed that you're choosing to learn something new.

Have a great day.
Robin S.
---------------------------------------------------------
 
J

J French

But calling the work of others "crap" is not a professional or reasoned
position. Every language has it's good sides and bad sides.

The problem is that if we get dotnet questions here then people get
confused
- it is like posting a C++ question here
 
G

Guest

You're absolutely right, J, my mistake, sorry about that.

I'm not sure if these discussions groups are moderated in any way, but I
imagine that people mistakenly posting to incorrect groups is not an uncommon
occurrence. After all, posting my question to a Classic VB forum doesn't
help me to solve my current problem.

Steve
 
M

Mike Coon

J said:
The problem is that if we get dotnet questions here then people get
confused
- it is like posting a C++ question here

Where, in that major list of cross-posted groups is "here"? (Rhetorical
question only!)

Mike.
--
 
J

J French

You're absolutely right, J, my mistake, sorry about that.

I'm not sure if these discussions groups are moderated in any way, but I
imagine that people mistakenly posting to incorrect groups is not an uncommon
occurrence. After all, posting my question to a Classic VB forum doesn't
help me to solve my current problem.

It looks as if there is a bit of automatic moderation for foul
language, but we can get round that.

Mostly we are a bunch of old timers who try to pass our acquired
mistakes onto others
- not easy when 'others' are using another language

It gets quite funny when a VB'er produces a comprehensive reply for a
..net'er and neither understands why it does not work.

We are a bit cliquey - that happens over time - over time you get to
like or loathe people.
- and we do need to keep the old ( and un-renameable ) NGs clear of
obfuscation.
 
N

Neila

We are a bit cliquey - that happens over time - over time you get to
like or loathe people.
LOL, I like to loathe all you wonderful people!!!
OTOH, I Loathe to like you all.....
Anybody wanting to do the P2S in VB Classic just ask!
Hell, I'll even take it to the next level!!!!!
Leave it to you Clicky old farts to dig up the API Declarations ;-)
HTH, Neila

-------
Public Sub GetStringArrayFromPointer(pStringArray As Long, _
strArray() As Variant, _
lngLabelCount As Long)
'Returns an Array of strings from a Pointer
Dim lngValue As Long
Dim lngLabPtrs() As Long
Dim strValue As String

ReDim lngLabPtrs(lngLabelCount - 1)
ReDim strArray(lngLabelCount - 1)
If lngLabelCount > 0 Then
'We have a pointer to an array of Pointers
'Blast them into the right slots
Call CopyMemory(lngLabPtrs(0), ByVal pStringArray, 4 *
lngLabelCount)

'Now dereference each of the pointers to get the strings
For lngValue = 0 To lngLabelCount - 1
strValue = ANSIStringFromPointer(lngLabPtrs(lngValue))
strArray(lngValue) = StripNull(strValue)
Next
End If
End Sub

Public Function ANSIStringFromPointer(ByVal lngStringPointer As Long)
As String
'Returns an ANSI string from a pointer to an ANSI string.
Dim strReturn As String
strReturn = VBA.String$(lstrlenA(ByVal lngStringPointer), 0)
Call lstrcpyA(ByVal strReturn, ByVal lngStringPointer)
ANSIStringFromPointer = strReturn
End Function
 
T

Tom Shelton

I'm trying to load this structure for a call to DeviceIoControl:

typedef struct _NDISUIO_QUERY_OID {
NDIS_OID Oid;
PTCHAR ptcDeviceName;
UCHAR Data[sizeof(ULONG)];
} NDISUIO_QUERY_OID, *PNDISUIO_QUERY_OID;

I created the equivalent in VB:

<StructLayout(LayoutKind.Sequential)> _
Public Class NDISUIO_QUERY_OID ' nuiouser.h
Public Oid As Int32
Public ptcDeviceName As IntPtr
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=4)> _
Public Data As String
End Class

What I need to proceed is: How do I get the pointer to my DeviceName string
to plug into ptcDeviceName? If it was C, I could just do ptcDeviceName =
&DeviceName -- I don't know how to do this in VB.

Thanks for any help,
Steve

Did anyone actually answer your question?
 
K

Karl E. Peterson

mobilemobile said:
But calling the work of others "crap" is not a professional or reasoned
position. Every language has it's good sides and bad sides.

Try reading this again:

In *no way* was I referring to anything other than your post itself. And, yes, it
is nothing shy of unmitigated crapola, in _some_ of the groups to which you spewed
it. Further, my response was hardly directed solely at you. That's a massive
misinterpretation of your relative importance in this universe. HTH!
 
G

Guest

As I suggested to another Classic VB poster, posting to a discussion group
incorrectly must occur here and there. A simple "sorry, this isn't a .NET
forum" would have sufficed. Both Classic VB and .NET forums are grouped
under Visual Basic only, and it was the first time I had posted to a VB forum
of any kind. I took a guess.

Your response was extreme enough to make me think that there was something
else going on. Sorry, I don't buy your explanation. Your website, with a
title that switches between Visual Basic.net and Visual Basic.not, has a long
list of complaints concerning the poor quality of the migration path from VB6
to VB.NET among other things.

I think it would be reasonable to assume that it simply bugged you that a
VB.NET user wandered into your clubhouse, that there is enmity there. The
funny part of it -- I also have a large VB6 code base.

Or, perhaps, you could accuse me of apostasy, by being a VB6 user now using
..NET.

All of which is not a "professional or reasoned position".
 
G

Guest

That's true of any group, J, not just the old ones. It's not a perfect world
though -- there's bound to be a wayward post.
 
K

Karl E. Peterson

mobilemobile said:
As I suggested to another Classic VB poster, posting to a discussion group
incorrectly must occur here and there.

It happens all the time here, yes, so it is a source of irritation to many.
A simple "sorry, this isn't a .NET
forum" would have sufficed.

Had you not cross-posted inappropriately, that's very true.
Both Classic VB and .NET forums are grouped
under Visual Basic only,

That, however, is not true. All the .NET groups actually contain the word
".dotnet." in their names.
and it was the first time I had posted to a VB forum
of any kind. I took a guess.

No problem. As I said, the response wasn't solely to you. Hopefully, others may
take it into consideration before making similarly uninformed guesses in the future.
Your response was extreme enough to make me think that there was something
else going on. Sorry, I don't buy your explanation.

Bite me.
Your website, with a
title that switches between Visual Basic.net and Visual Basic.not, has a long
list of complaints concerning the poor quality of the migration path from VB6
to VB.NET among other things.

Poor indeed. But characterizing the quotes found there as "complaints" as opposed
to "statements of reality" definitely positions _you_ as the one with a bias.
I think it would be reasonable to assume that it simply bugged you that a
VB.NET user wandered into your clubhouse, that there is enmity there.

Putting that Psych101 class to its highest use, are ya? Impressive.

(.NOT! said:
The funny part of it -- I also have a large VB6 code base.

Perhaps you misspelled "ironic" there? The general sense is that only Microsoft
sees this situation as humorous.
Or, perhaps, you could accuse me of apostasy, by being a VB6 user now using
.NET.

If you're not evangelizing, you're just attempting to get by, like the rest of us.
Your obvious defensiveness aside.
All of which is not a "professional or reasoned position".

What on earth led you to believe that's what you'd find on usenet? <LOL>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top