Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

704 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