PC Review


Reply
Thread Tools Rate Thread

C# conversion to VB .NET ?

 
 
Katie
Guest
Posts: n/a
 
      13th Sep 2003
Hi,
Im converting some C# RAPI code to VB .NET. The C# version works. However,
the VB version returns E_INVALIDARG

Does anyone see the conversion problem? i noted the lines that may be the
problem.

I know there are libraries available for RAPI but i can't use them

Thanks
Katie


C#
version --------------------------------------------------------------------
-----
[StructLayout(LayoutKind.Sequential)]
internal struct RAPIINIT
{
public int cbSize;
public IntPtr heRapiInit;
public int hrRapiInit;
}

public boolean TryRapiConnect()
{
// non-blocking init rapi call

private IntPtr hInitEvent = IntPtr.Zero;
private int InitResult = 0;
private RAPIINIT ri;
private int retVal = 0;

ri = new RAPIINIT();

ri.cbSize = Marshal.SizeOf(ri);
ri.hrRapiInit = InitResult;

hInitEvent = CreateEvent(IntPtr.Zero, 0, 0, "RapiInitEvent");

ri.heRapiInit = hInitEvent;

retVal = CeRapiInitEx(ref ri);

}

VB
version --------------------------------------------------------------------
--
<StructLayout(LayoutKind.Sequential)> _
Public Structure RAPIINIT
Dim cbSize As Integer
Dim heRapiInit As Integer
Dim hrRapiInit As Integer
End Structure

public Function TryRapiConnect() As Boolean
'non-blocking init rapi call

Dim hInitEvent As Integer = 0
Dim InitResult As Integer = 0
Dim ri As RAPIINIT
Dim retVal as integer = 0

ri = New RAPIINIT
ri.cbSize = Marshal.SizeOf(ri)
ri.hrRapiInit = 0

hInitEvent = CreateEvent(0, 0, 0, "RapiInitEvent") '<<< maybe problem
here with first arg

ri.heRapiInit = hInitEvent

retVal = CeRapiInitEx(ri) '<<< maybe problem here with arg. C# version
uses (ref ri). what should it be in VB?

End Function


 
Reply With Quote
 
 
 
 
Katie
Guest
Posts: n/a
 
      13th Sep 2003
here is the dllimport for C# and VB .NET
C#----
[DllImport("rapi.dll", CharSet=CharSet.Unicode)]
internal static extern int CeRapiInitEx ([MarshalAs(UnmanagedType.Struct)]
ref RAPIINIT pRapiInit);

VB---
<DllImport("rapi.dll", CharSet:=CharSet.Unicode)> _
Private Shared Function CeRapiInitEx(<MarshalAs(UnmanagedType.Struct)>
ByVal prapiinit As RAPIINIT) As Integer
End Function

"Katie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> Im converting some C# RAPI code to VB .NET. The C# version works. However,
> the VB version returns E_INVALIDARG
>
> Does anyone see the conversion problem? i noted the lines that may be the
> problem.
>
> I know there are libraries available for RAPI but i can't use them
>
> Thanks
> Katie
>
>
> C#
>

version --------------------------------------------------------------------
> -----
> [StructLayout(LayoutKind.Sequential)]
> internal struct RAPIINIT
> {
> public int cbSize;
> public IntPtr heRapiInit;
> public int hrRapiInit;
> }
>
> public boolean TryRapiConnect()
> {
> // non-blocking init rapi call
>
> private IntPtr hInitEvent = IntPtr.Zero;
> private int InitResult = 0;
> private RAPIINIT ri;
> private int retVal = 0;
>
> ri = new RAPIINIT();
>
> ri.cbSize = Marshal.SizeOf(ri);
> ri.hrRapiInit = InitResult;
>
> hInitEvent = CreateEvent(IntPtr.Zero, 0, 0, "RapiInitEvent");
>
> ri.heRapiInit = hInitEvent;
>
> retVal = CeRapiInitEx(ref ri);
>
> }
>
> VB
>

version --------------------------------------------------------------------
> --
> <StructLayout(LayoutKind.Sequential)> _
> Public Structure RAPIINIT
> Dim cbSize As Integer
> Dim heRapiInit As Integer
> Dim hrRapiInit As Integer
> End Structure
>
> public Function TryRapiConnect() As Boolean
> 'non-blocking init rapi call
>
> Dim hInitEvent As Integer = 0
> Dim InitResult As Integer = 0
> Dim ri As RAPIINIT
> Dim retVal as integer = 0
>
> ri = New RAPIINIT
> ri.cbSize = Marshal.SizeOf(ri)
> ri.hrRapiInit = 0
>
> hInitEvent = CreateEvent(0, 0, 0, "RapiInitEvent") '<<< maybe problem
> here with first arg
>
> ri.heRapiInit = hInitEvent
>
> retVal = CeRapiInitEx(ri) '<<< maybe problem here with arg. C#

version
> uses (ref ri). what should it be in VB?
>
> End Function
>
>



 
Reply With Quote
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      14th Sep 2003
Your C# declaration is passing by reference (ref), and your VB version is
passing by value (ByVal), changing this in your VB code to ByRef should fix
it.

Peter

--
Peter Foot
Windows Embedded MVP

In The Hand
http://www.inthehand.com

"Katie" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> here is the dllimport for C# and VB .NET
> C#----
> [DllImport("rapi.dll", CharSet=CharSet.Unicode)]
> internal static extern int CeRapiInitEx

([MarshalAs(UnmanagedType.Struct)]
> ref RAPIINIT pRapiInit);
>
> VB---
> <DllImport("rapi.dll", CharSet:=CharSet.Unicode)> _
> Private Shared Function CeRapiInitEx(<MarshalAs(UnmanagedType.Struct)>
> ByVal prapiinit As RAPIINIT) As Integer
> End Function
>
> "Katie" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi,
> > Im converting some C# RAPI code to VB .NET. The C# version works.

However,
> > the VB version returns E_INVALIDARG
> >
> > Does anyone see the conversion problem? i noted the lines that may be

the
> > problem.
> >
> > I know there are libraries available for RAPI but i can't use them
> >
> > Thanks
> > Katie
> >
> >
> > C#
> >

>

version --------------------------------------------------------------------
> > -----
> > [StructLayout(LayoutKind.Sequential)]
> > internal struct RAPIINIT
> > {
> > public int cbSize;
> > public IntPtr heRapiInit;
> > public int hrRapiInit;
> > }
> >
> > public boolean TryRapiConnect()
> > {
> > // non-blocking init rapi call
> >
> > private IntPtr hInitEvent = IntPtr.Zero;
> > private int InitResult = 0;
> > private RAPIINIT ri;
> > private int retVal = 0;
> >
> > ri = new RAPIINIT();
> >
> > ri.cbSize = Marshal.SizeOf(ri);
> > ri.hrRapiInit = InitResult;
> >
> > hInitEvent = CreateEvent(IntPtr.Zero, 0, 0, "RapiInitEvent");
> >
> > ri.heRapiInit = hInitEvent;
> >
> > retVal = CeRapiInitEx(ref ri);
> >
> > }
> >
> > VB
> >

>

version --------------------------------------------------------------------
> > --
> > <StructLayout(LayoutKind.Sequential)> _
> > Public Structure RAPIINIT
> > Dim cbSize As Integer
> > Dim heRapiInit As Integer
> > Dim hrRapiInit As Integer
> > End Structure
> >
> > public Function TryRapiConnect() As Boolean
> > 'non-blocking init rapi call
> >
> > Dim hInitEvent As Integer = 0
> > Dim InitResult As Integer = 0
> > Dim ri As RAPIINIT
> > Dim retVal as integer = 0
> >
> > ri = New RAPIINIT
> > ri.cbSize = Marshal.SizeOf(ri)
> > ri.hrRapiInit = 0
> >
> > hInitEvent = CreateEvent(0, 0, 0, "RapiInitEvent") '<<< maybe

problem
> > here with first arg
> >
> > ri.heRapiInit = hInitEvent
> >
> > retVal = CeRapiInitEx(ri) '<<< maybe problem here with arg. C#

> version
> > uses (ref ri). what should it be in VB?
> >
> > End Function
> >
> >

>
>



 
Reply With Quote
 
Chris Tacke, eMVP
Guest
Posts: n/a
 
      15th Sep 2003
Out of curiosity, why not just use the OpenNETCF RAPI dll as it is?

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


"Katie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> Im converting some C# RAPI code to VB .NET. The C# version works. However,
> the VB version returns E_INVALIDARG
>
> Does anyone see the conversion problem? i noted the lines that may be the
> problem.
>
> I know there are libraries available for RAPI but i can't use them
>
> Thanks
> Katie
>
>
> C#
>

version --------------------------------------------------------------------
> -----
> [StructLayout(LayoutKind.Sequential)]
> internal struct RAPIINIT
> {
> public int cbSize;
> public IntPtr heRapiInit;
> public int hrRapiInit;
> }
>
> public boolean TryRapiConnect()
> {
> // non-blocking init rapi call
>
> private IntPtr hInitEvent = IntPtr.Zero;
> private int InitResult = 0;
> private RAPIINIT ri;
> private int retVal = 0;
>
> ri = new RAPIINIT();
>
> ri.cbSize = Marshal.SizeOf(ri);
> ri.hrRapiInit = InitResult;
>
> hInitEvent = CreateEvent(IntPtr.Zero, 0, 0, "RapiInitEvent");
>
> ri.heRapiInit = hInitEvent;
>
> retVal = CeRapiInitEx(ref ri);
>
> }
>
> VB
>

version --------------------------------------------------------------------
> --
> <StructLayout(LayoutKind.Sequential)> _
> Public Structure RAPIINIT
> Dim cbSize As Integer
> Dim heRapiInit As Integer
> Dim hrRapiInit As Integer
> End Structure
>
> public Function TryRapiConnect() As Boolean
> 'non-blocking init rapi call
>
> Dim hInitEvent As Integer = 0
> Dim InitResult As Integer = 0
> Dim ri As RAPIINIT
> Dim retVal as integer = 0
>
> ri = New RAPIINIT
> ri.cbSize = Marshal.SizeOf(ri)
> ri.hrRapiInit = 0
>
> hInitEvent = CreateEvent(0, 0, 0, "RapiInitEvent") '<<< maybe problem
> here with first arg
>
> ri.heRapiInit = hInitEvent
>
> retVal = CeRapiInitEx(ri) '<<< maybe problem here with arg. C#

version
> uses (ref ri). what should it be in VB?
>
> End Function
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conversion from Access 97 to 2003 & get a "Conversion Errors" tabl eidinger2000 Microsoft Access 0 4th Feb 2010 04:19 PM
Conversion errors where no conversion needed jbeckh2@gmail.com Microsoft Dot NET Framework 0 12th Jan 2007 07:24 PM
VB Conversion Keywords And .NET Conversion Routines rawCoder Microsoft VB .NET 43 2nd Mar 2005 02:56 PM
VB Conversion Keywords And .NET Conversion Routines rawCoder Microsoft VB .NET 2 28th Feb 2005 06:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:29 AM.