Using VB.NET

  • Thread starter Thread starter Nak
  • Start date Start date
N

Nak

Hi there,

I am trying to convert the following to VB.NET code, it is a C# wrapper
for a C++ DLL,

using PVOID = IntPtr;
using FIBITMAP = Int32;
using FIMULTIBITMAP = Int32;

As I understand it, the objects on the right are being given the aliases
on the left, so PVOID objects are actually IntPrt objects (or so I
understand anyway. How would I write this in VB.NET? I could just remove
all aliases, but I thought I would quickly ask as this one has got me.
Thanks loads.

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
* "Nak said:
I am trying to convert the following to VB.NET code, it is a C# wrapper
for a C++ DLL,

using PVOID = IntPtr;
using FIBITMAP = Int32;
using FIMULTIBITMAP = Int32;

As I understand it, the objects on the right are being given the aliases
on the left, so PVOID objects are actually IntPrt objects (or so I
understand anyway. How would I write this in VB.NET?

Something like 'Imports PVIOD = System.IntPtr' (untested)?
 
I would expect that these are types in the C++ dl. Since these types do not
exist in VB.Net they need to be replaced.
Therefore, a function such as:
\\\
<DllImport("MyLib")> _
Private Shared Function MyUnknownFunction ( _
ByVal Arg1 as PVOID, _
ByVal Arg2 As FIBITMAP) As
FIMULTIBITMAP
End Function
///
would translate to:
\\\
<DllImport("MyLib")> _
Private Shared Function MyUnknownFunction ( _
ByVal Arg1 as Intptr, _
ByVal Arg2 As Int32) As Int32
End Function
///
allowing VB.Net to understand the Types Passed.

I may be wrong, but that makes sense to me.
 
Hi Herfried,
Something like 'Imports PVIOD = System.IntPtr' (untested)?

Unfortunately it doesn't find it, I'm getting the error message,

"Namespace or type 'IntPtr' for the imports 'IntPrt' cannot be found.

It looks like I may have to replace everything instead, which is a bugger!
Oh well :-(

Nick.
--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Hi Mick,
I would expect that these are types in the C++ dl. Since these types do not
exist in VB.Net they need to be replaced.

I understand what you are saying but the actual lines I am trying to find VB
replacements for simply give a type an alias. Such as

Using pastrami = Int;

pastrami badger = 50;

^ In essence this declares an integer with a value of 50.

I've started simply removing the alias's now, which could cause confusion at
a later date, I shall see :-\

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Hi Nick, Herfried,


Did you get the spelling right - I notice both 'IntPtr' and 'IntPrt' in
your post?

I tried it and it worked fine.

Imports PVOID = System.IntPtr
Dim ThisPVoid As PVOID = PVOID.Zero
S$ = ThisPVoid.ToInt64.ToString

Can't do a lot with it mind - just set it to zero and pass it around. But
that's enough, I gather.

Regards,
Fergus
 
* "Nak said:
Unfortunately it doesn't find it, I'm getting the error message,

"Namespace or type 'IntPtr' for the imports 'IntPrt' cannot be found.

It looks like I may have to replace everything instead, which is a bugger!
Oh well :-(

Are you sure you typed the fully qualified name ('System.IntPtr' instead
of 'IntPtr'? This works for me on .NET 1.1.
 
Nick,
Herfried's suggestion should work, I'm not sure why you would get an error.

Are you on VS.NET 2002 or VS.NET 2003, the following works in VS.NET 2003.

Option Strict On
Option Explicit On

Imports PVOID = System.IntPtr
Imports FIBITMAP = System.Int32
Imports FIMULTIBITMAP = System.Int32


<DllImport("MyLib")> _
Private Shared Function MyUnknownFunction ( _
ByVal Arg1 as PVOID, _
ByVal Arg2 As FIBITMAP) _
As FIMULTIBITMAP

Note you need the fully qualified name on the import, System.Int32, not just
Int32.

Just remember that you are defining an Alias, not a new type when you use
the Imports Alias.

Hope this helps
Jay
 
* "Fergus Cooney said:
Did you get the spelling right - I notice both 'IntPtr' and 'IntPrt' in
your post?

I tried it and it worked fine.

Imports PVOID = System.IntPtr
Dim ThisPVoid As PVOID = PVOID.Zero
S$ = ThisPVoid.ToInt64.ToString

I prefer:

\\\
Dim s As String = ThisPVoid.ToInt64().ToString()
///

;-)
Can't do a lot with it mind - just set it to zero and pass it around. But
that's enough, I gather.

Works fine for me too.
 
Hi there,

AAaaah I needed the system part! (System.IntPtr), I thought it would
find it regardless, woops :-) Thanks

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Hi Herfried,
Are you sure you typed the fully qualified name ('System.IntPtr' instead
of 'IntPtr'? This works for me on .NET 1.1.

I missed out the full name, all is well now, thanks :-) I thought it might
be something I was doing wrong.

Imports pastrami = System.Int32 sorted!

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Hi Nick,

And now I know that I can alias types - I wasn't aware of that before.
Should be able to confuse a couple of junior programmers with that at some
time.

Keep up with the questions, Nick, I'm learning about remoting and
security, obfuscalating and everything.


pastrami badger = 50

ROFL

badger.beatwith (GetType (badger))

Regarts,
Fergus
 
Hi Fergus,
Keep up with the questions, Nick, I'm learning about remoting and
security, obfuscalating and everything.

I've got a lovely remote server in development at the moment which requires
login and such like, all of this to access my database files via a proxy for
increased security!
badger.beatwith (GetType (badger))

ROFL, could a badger be type casted to a "stoutStick"?

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
Back
Top