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
181 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to delete range 4 54
Replace Formatted Numbers with text 9 51
Use Multiple Forms 4 38
String manipulation in Visual Basic 7 44
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

758 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

17 Experts available now in Live!

Get 1:1 Help Now