Re: External Interfacing: pointer to pointer...



Chris,

I am trying to interface with the winpcap DLL. This function has been driving me crazy:

int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);

This is how I have defined it in Smalltalk:

<stdcall: dword pcap_next_ex lpvoid lpvoid* lpvoid*>

I can call it, and I get a return code that indicates success. This is how I am calling it:

header := ExternalAddress new.
data := ExternalAddress new.
wp pcap_next_ex: wph header: header data: data.

The problem I have is getting the data in header and data. This is how I try to get the header data:

[snip]

This is probably one of those situations in which one must out-smart Dolphin's desire to pass by reference. At least I find it easier to assume that than that you have made a mistake elsewhere.

The most recent struggle I recall was in wrapping the GNU Scientific Library. I don't know that I ever figured out why what I finally did works, but it clearly does. Specifically, GSL specifies algorithms (e.g. bisection, Newton-Raphson) by exports from the DLL. I am not sure if they are pointers to data or functions (probably the latter), but getting the correct addresses was tricky. I will take a look at how I solved that and report back later. How much use it will be is in question though; you would probably have to dive into the GSL Win32 source to decide whether it is in fact the same thing.

Another example that comes to mind will be a little harder to track down. I was implementing a COM component that had to pass a pointer on to another COM component, or something like that. Pass by reference really got in the way. IIRC, I had to create an intermediate byte object to allow the VM to strip away the indirection, ending up with the correct value in the receiver. I still suspect that the reference convention prevents more trouble than it causes, but it can be a big pain at times.

The example above will be a little hard to find, as it involves DCOM. Given how long ago I stopped trusting a certain vendor, that goes back more than a few years. I will see what I can do.

Bill


--
Wilhelm K. Schwab, Ph.D.
bills@xxxxxxxxxxxxxxxxxxxx
.



Relevant Pages

  • Re: Real World Flunks (Re: Why is Object Oriented so successful)
    ... AndyW wrote: ... "modeling the real world". ... CADD screen closely matches the object pointers in a typical real- ... I think the fact one has a reference to it ...
    (comp.object)
  • Re: The Java no pointer big fat lie!
    ... > reference types, it wouldn't be a good comparison. ... and what you can't - and there is a big difference in Java to C and C++. ... You cannot change it in the language itself, ... Thus I would distinguish pointers from ...
    (comp.lang.java.programmer)
  • Re: Catching the New Page event in VBA
    ... Thanks for your reply, Doug. ... When, or if, the user starts a new page the different header will be used ... The reference number and the subject of the ... Private Sub wdApp_WindowSelectionChange ...
    (microsoft.public.word.vba.general)
  • Re: Modifying Class Object
    ... your argument that the copied reference does not exist, ... But since it does have an effect, a memory change has been effected. ... By which you mean that henceforth, until the next assignment to t, t *refers* to the same object as s. ... But a linked list can be implemented in Python, using names as pointers. ...
    (comp.lang.python)
  • Re: Catching the New Page event in VBA
    ... including the primary header (the one that will appear on the ... The reference number and the subject of the ... Dim page2 As Integer ... Private Sub wdApp_WindowSelectionChange ...
    (microsoft.public.word.vba.general)