Solved

How can I recognize/parse the structure of UDT, returned from C dll, if I get the pointer to this structure in a VBA function?

Posted on 2004-10-11
3
184 Views
Last Modified: 2010-05-02
A C dll returns a pointer (lngPointer) to a big UDT structure (appr. 60 primitive types fields, differently groupped), created by this dll. I don't know exactly, what are the fields of this structure and what size do they have. Can I recognize/specify it from VBA code somehow?
In particular, to find the size of the whole structure, and the sizes of all fields, as the follow each other?
0
Comment
Question by:inversojvo
  • 2
3 Comments
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 12278411
You may have to contact the author(s) of the DLL for the correct UDT structure if they don't offer documentation. There may be reverse-engineering methods but if you have permission/license(s) to use the DLL, I see no problem with asking for the structure. Once you have it, you can just define it within your project and CopyMemory() from the pointer using the length of the (correctly) defined UDT. An example below.

Form1:
----------------------------
Option Explicit

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)

Private Type MyUDT
    var1 As String
    var2 As Long
End Type
Private Sub Form_Load()
    Dim udtIn As MyUDT, udtOut As MyUDT
    Dim lngPtr As Long
    'assign values to udtIn
    udtIn.var1 = "test"
    udtIn.var2 = "1234"
    'get the pointer to udtIn
    lngPtr = VarPtr(udtIn)
    'copy udtIn to udtOut using it's pointer
    Call CopyMemory(ByVal VarPtr(udtOut), ByVal lngPtr, Len(udtOut))
    'test it..
    Call MsgBox(udtOut.var1 & "," & udtOut.var2)
End Sub
0
 

Author Comment

by:inversojvo
ID: 12278991
> You may have to contact the author(s) of the DLL for the correct UDT structure

Yes, this is a possible way, but I'm interested namely in getting this info without documentation and addressing the authors. In my case the addressing the author is a administrative way, and the query will go, I think, 3 days one way, and then 3 days back :).

The idea was to recognize somehow or the end of the structure (f.ex. to read byte after byte untill the end of the structure will be found - but I don't know, how the end of the structure is marked - if it's marked at all). Or to get the size, like for BSTR strings, when the pointer points at the beginning of the string, but just before the beginning the length of the BSTR string is marked.

So, I need or the answer, how to do it technically, or the provement, that it's impossible to do from VBA.

This question, in fact, was derivated from another thread: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21161325.html

0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 400 total points
ID: 12283916
>>Or to get the size
I don't believe you'll be able to determine the length of the structure without knowing the structure itself since it'd just be a sequence of bytes for all of the variables. From memory-dumps, that's true for VB and *should* be the same for C.

>>like for BSTR strings
UDTs define the structure so you can easily get the length from combining the bytes used for all of the variables (and possible padding). Strings don't have that method since they can vary in size so they require a method that BSTR implements (or null-termination for C). Because of that, I don't think UDTs have additional overhead just to offer another means to get their lengths. I'm not entirely sure though so there's still hope that somebody knows. :)

>>This question, in fact, was derivated from another thread
You may want to keep with your original plan in finding the correct UDT. I'm not too familiar with C/C++ so I can't offer much help. Sorry.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Determine Range to Select 5 42
Spell Check in VB6 13 95
Passing a Text Box name to a Sub 6 71
I need help using System.Web.HttpUtility.HtmlEncode in my VB.Net application 3 54
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now