Click to See Complete Forum and Search --> : VarPtr workaround in VB.Net


Codeine519
March 29th, 2004, 11:49 AM
I am attempting to read the table of contents from a CD, in order to generate the ID number to pass to a CDDB server for a little project I am working on.

Using code snippets from http://www.hochfeiler.it/alvise/aspi_VB.htm , it shows an example using VarPtr().

I have found out that VarPtr is not supported in Visual Basic .Net. Is there any work around, or any suggestions on what to do for this particular problem. Every example that I have found for doing what I want to do is written in Visual Basic 6 code, and I am trying to write it using VB.Net

Any help would be appreciated. Thank you,

Codeine519

DSJ
March 29th, 2004, 12:02 PM
Try This:

'Replace XXX with your object variable...
Dim gc As System.Runtime.InteropServices.GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(xxx, System.Runtime.InteropServices.GCHandleType.Pinned)
Dim i As Int32 = gc.AddrOfPinnedObject.ToInt32

Craig Gemmill
March 29th, 2004, 12:07 PM
Here is an alternative method:
http://www.vbaccelerator.com/home/VB/Code/vbMedia/CD_TrackListings/article.asp

Codeine519
March 29th, 2004, 05:43 PM
DSJ - I tried the following code, like you suggested

Dim gc As GCHandle = GCHandle.Alloc(CurTOC, GCHandleType.Pinned)
Dim i As Int32 = gc.AddrOfPinnedObject.ToInt32

But it gave me the follwing exception
Additional information: Object contains non-primitive or non-blittable data

The structures used are as follows

Structure TOC_Track
Dim Rsvd1 As Byte
Dim ADR As Byte
Dim Track As Byte
Dim Rsvd2 As Byte
Dim Addr() As Byte
End Structure

Structure TOC
Dim TocLen() As Byte
Dim FirstTrack As Byte
Dim LastTrack As Byte
Dim TocTrack() As TOC_Track
End Structure

Any idea what may be causing that? I think it might be the TOCTrack() in the TOC, but I am not sure.

Craig(Gemmill) - I looked at that page, thank you. I got some of the algorithms off that page.

Thanks for trying to help, any other ideas will be appreciated. Is it possible it might be better to calculate the disk id from a C++ dll, then send it to the Visual Basic program?