Results 1 to 3 of 3

Thread: [2005] VarPtr replacement

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    10

    [2005] VarPtr replacement

    Hey...
    I posted some weird errors w.r.t. OCX and DLL's last night.But,I didn't get any reply to that...So,now I am posting a line of the same code which was written in VB and I need to convert it to VB.Net. The thing is VB.Net doesn't support VarPtr and hence,I dunno how to convert this particular statement...

    CSRF12.GetCurrentUID VarPtr(bUID(0))

    CSRF12 is name of a object on my VB form with which the GetCurrentUID method is associated.bUID is an array of size 8.It stores the incoming RFID Tag ID.So,when I try to write this line as

    AxCSRF1.GetCurrentUID (bUID(0)),
    I get the exception:
    A first chance exception of Type 'System.Runtime.InteropServices.COMException' occurred in AxInterop.Rfx.dll

    in the output window.Can anyone help me find a solution to this??

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] VarPtr replacement

    A first chance exception does not always mean something is wrong. It just means an exception was encountered by the runtime. Many first chance exceptions are reported, but handled in the runtime, so they never filter all the way up to throw an exception in your code itself.

    This may or may not be the case for you. The question is, is the app working, or is it not working, regardless of the first chance exception?

    Also there are some ways to get the same functionality from some VB6 functions in .NET.

    Code:
    Public Function VarPtr(ByVal o As Object) As Integer
    
    Dim GC As System.Runtime.InteropServices.GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(o, System.Runtime.InteropServices.GCHandleType.Pinned)
    
    Dim ret As Integer = GC.AddrOfPinnedObject.ToInt32
    
    GC.Free()
    
    Return ret
    
    End Function
    I originally found that code here (gotta give credit where its due )

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2007
    Posts
    10

    Re: [2005] VarPtr replacement

    Hey...
    Thanx a lot for ur reply...I used the VarPtr function declaration that you hav provided in the previous reply...The Exception I used to get earlier now does not exist but I am not getting the desired output.I will clarify what I imply by providing the code which has the bugs....

    CSRF12.GetCurrentUID VarPtr(bUID(0))

    This is a statement in VB which returns the UID in bUID which is a byte array of size 8.The UID gets stored sequentially from the 0th location upto the 7th location.

    Now following is a statement in VB.Net :

    AxCSRF1.GetCurrentUID(VarPtr(bUID(0)))

    AxCSRF1 is the name of the object of the ActiveX component whose name is CSRF12 in the previous case.VarPtr is obviously the user-defined function seen in the previous reply.The parentheses after GetCurrentUID is inserted automatically by Visual Studio 2005.Now,my problem is this.After executing the above statement in VB.Net,bUID contains no value. In the VB code,the UID used to be stored in it.So,now I need to know how to use VarPtr to get the desired value.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width