473,473 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VB6 -> VB.Net

I need some help. The following third-part VB6 code works:

Type cdSourceInfo
SourceType As Long
rsrvd As Long Name As String * 64
NameInOS As String * 64
PortType As Long
u As cdPortDescripUnion
End Type

Declare Function CDEnumDeviceNext Lib "CDSDK.dll" (ByVal hEnum As Long,
ByRef pSourceInfo As cdSourceInfo) As Long

Private SourceInfo As cdSourceInfo
err = CDEnumDeviceNext(hEnum, SourceInfo)

The dll is unmanaged.

My conversion of this is:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> Structure
cdSourceInfo
Public SourceType As Integer
Public rsrvd As Integer
<VBFixedString(64)> Public Name As String
<VBFixedString(64)> Public NameInOS As String Public PortType As Integer
Public u As cdPortDescripUnion
End Structure

Declare Function CDEnumDeviceNext Lib "CDSDK.dll" (ByVal hEnum As Integer,
ByRef pSourceInfo As cdSourceInfo) As Integer

Private m_sourceInfo As cdSourceInfo
SourceInfo = New cdSourceInfo()
err = CDEnumDeviceNext(hEnum, SourceInfo)
I get a null-reference exception here.
Can someone guess as to what I'm doing wrong?

Ken
Nov 20 '05 #1
3 1957
Promblem is most likely the string members of the structure. You need to
initialize those. VBFixedString won't help you here.

-Rob Teixeira [MVP]

"Ken Kast" <ke*@NOSPAMkenkast.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I need some help. The following third-part VB6 code works:

Type cdSourceInfo
SourceType As Long
rsrvd As Long Name As String * 64
NameInOS As String * 64
PortType As Long
u As cdPortDescripUnion
End Type

Declare Function CDEnumDeviceNext Lib "CDSDK.dll" (ByVal hEnum As Long,
ByRef pSourceInfo As cdSourceInfo) As Long

Private SourceInfo As cdSourceInfo
err = CDEnumDeviceNext(hEnum, SourceInfo)

The dll is unmanaged.

My conversion of this is:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> Structure
cdSourceInfo
Public SourceType As Integer
Public rsrvd As Integer
<VBFixedString(64)> Public Name As String
<VBFixedString(64)> Public NameInOS As String Public PortType As Integer
Public u As cdPortDescripUnion
End Structure

Declare Function CDEnumDeviceNext Lib "CDSDK.dll" (ByVal hEnum As Integer,
ByRef pSourceInfo As cdSourceInfo) As Integer

Private m_sourceInfo As cdSourceInfo
SourceInfo = New cdSourceInfo()
err = CDEnumDeviceNext(hEnum, SourceInfo)
I get a null-reference exception here.
Can someone guess as to what I'm doing wrong?

Ken

Nov 20 '05 #2
"Ken Kast" <ke*@NOSPAMkenkast.com> schrieb
I need some help. The following third-part VB6 code works:

Type cdSourceInfo
SourceType As Long
rsrvd As Long Name As String * 64
NameInOS As String * 64
PortType As Long
u As cdPortDescripUnion
End Type

Declare Function CDEnumDeviceNext Lib "CDSDK.dll" (ByVal hEnum As
Long, ByRef pSourceInfo As cdSourceInfo) As Long

Private SourceInfo As cdSourceInfo
err = CDEnumDeviceNext(hEnum, SourceInfo)

The dll is unmanaged.

My conversion of this is:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)>
Structure cdSourceInfo
Public SourceType As Integer
Public rsrvd As Integer
<VBFixedString(64)> Public Name As String
<VBFixedString(64)> Public NameInOS As String
Public PortType As Integer
Public u As cdPortDescripUnion
End Structure

Declare Function CDEnumDeviceNext Lib "CDSDK.dll" (ByVal hEnum As
Integer, ByRef pSourceInfo As cdSourceInfo) As Integer

Private m_sourceInfo As cdSourceInfo
SourceInfo = New cdSourceInfo()
err = CDEnumDeviceNext(hEnum, SourceInfo)
I get a null-reference exception here.
Can someone guess as to what I'm doing wrong?

Try to add the MarshalAs attribute to the fixed strings:

Imports System.Runtime.InteropServices.

Private Structure cdSourceInfo
Dim SourceType As Integer
Dim rsrvd As Integer
<VBFixedString(64), MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)>
Public Name As String
<VBFixedString(64),MarshalAs(UnmanagedType.ByValTS tr,SizeConst:=64)>
Public NameInOS As String
Dim PortType As Integer
Dim u As cdPortDescripUnion
End Structure
BTW, why don't you use the upgrade wizard? It automatically added the
attributes.

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
Rob, Armin, you were both right. It took both of your recommendations to
make the code work. To implement Rob's I added a method to initialize the
string to null, then pad it. I actually haven't checked if the padding is
needed.

Ken

"Ken Kast" <ke*@NOSPAMkenkast.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I need some help. The following third-part VB6 code works:

Type cdSourceInfo
SourceType As Long
rsrvd As Long Name As String * 64
NameInOS As String * 64
PortType As Long
u As cdPortDescripUnion
End Type

Declare Function CDEnumDeviceNext Lib "CDSDK.dll" (ByVal hEnum As Long,
ByRef pSourceInfo As cdSourceInfo) As Long

Private SourceInfo As cdSourceInfo
err = CDEnumDeviceNext(hEnum, SourceInfo)

The dll is unmanaged.

My conversion of this is:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> Structure
cdSourceInfo
Public SourceType As Integer
Public rsrvd As Integer
<VBFixedString(64)> Public Name As String
<VBFixedString(64)> Public NameInOS As String Public PortType As Integer
Public u As cdPortDescripUnion
End Structure

Declare Function CDEnumDeviceNext Lib "CDSDK.dll" (ByVal hEnum As Integer,
ByRef pSourceInfo As cdSourceInfo) As Integer

Private m_sourceInfo As cdSourceInfo
SourceInfo = New cdSourceInfo()
err = CDEnumDeviceNext(hEnum, SourceInfo)
I get a null-reference exception here.
Can someone guess as to what I'm doing wrong?

Ken

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
2
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
0
by: Arne Schirmacher | last post by:
I want to display a MySQL database field that can contain HTML markup. If I use <esql:get-string> then I get all of the database field, but all tags are escaped which is not what I want. If I use...
34
by: Mark Moore | last post by:
It looks like there's a pretty serious CSS bug in IE6 (v6.0.2800.1106). The HTML below is validated STRICT HTML 4.01 and renders as I would expect in Opera, FrontPage, and Netscape. For some...
11
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom,...
2
by: bissatch | last post by:
Hi, I am currently writing a simple PHP program that uses an XML file to output rows for a 'Whats New' page. Once written, I will only require updating the XML file and any pages that use the...
0
by: vdex42 | last post by:
Apologies if this has been asked before, but I haven't been able to find the answer to this yet: My problem is that .NET will not allow me to insert escaped '>' characters (i.e. &gt;) within the...
2
by: santaji | last post by:
I am getting xml string in request attribute in following format &lt;files&gt; &lt;file&gt; &lt;filename&gt;somefile.ext&lt;/filename&gt; &lt;/file&gt; &lt;files&gt; the above string I want to convert to tags. expected...
1
by: VaidehiPawar | last post by:
I am a beginner level in xml..my output page does not convert &gt &lt it shows something like this " &lt;b&gt;Location.&lt;/b&gt;&lt;br /&gt; &lt;UL&gt;&lt;LI&gt;Park Central New York " can anyone help? here is my code ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.