title: passing pointers to extern C function in a DLL from VB
body: <p>I am a C++ (MSVC) writer, VB newbie trying to assist an expert VB.net writer who has just not done this task before. </p>
  
  <p>We wish to develop both C/C++ and VB applications to use a DLL written in C++ with C extern-ed API functions.  The C++ program is working just fine.  It's VB where we are having difficulties.</p>
  
  <p>The DLL provides an <code>extern C</code> function:</p>
  
  <pre><code>RegisterCallback( void* cbFuncPtr, void* dataPtr );
  </code></pre>
  
  <p><strong>NOTE 1:  See my note below for a design change and the reasons we made it.</strong></p>
  
  <p><strong>NOTE 2: Additional update added as an answer below.</strong></p>
  
  <p>where the callback function havs this C typedef:</p>
  
  <pre><code>typedef   (void)(* CALL_NACK)(void*);
  </code></pre>
  
  <p>The <code>cbFuncPtr</code> is expected to be a function pointer to some VB function that will get  called as the CALL_BACK.  The <code>dataPtr</code> is a pointer to a data structure that has this C definition:</p>
  
  <pre><code>typedef struct 
  {
     int      retCode;
     void*    a_C_ptr;
     char     message[500];
  }  cbResponse_t;
  </code></pre>
  
  <p>where <code>a_C_ptr is an internal pointer in the DLL that the VB can cast to</code>long`.  It uniquely identifies where in the DLL the callback was made and allows the VB function to recognize calls from same/different locations. </p>
  
  <p>We are able to access and run the <code>RegisterCallback()</code> function from VB just fine.  Logging shows we get there and that data is passed in.  It is the actual data that seems to be the problem.</p>
  
  <p>In reading about a million forum entries we have learned that VB doesn't know what pointers are and that a VB structure is more than just organized memory.  We're pretty sure the "address" of a VB structure is not what C thinks an address is.  We've seen repeated references to "marshaling" and "managed data", but lack enough understanding to know what that is telling us.</p>
  
  <p>How should we code VB to give the DLL the execution address of its callback function and how do we code up a VB construct that the DLL can fill in just as it does for C++?</p>
  
  <p>Might we need a DLL function where the calling app can say "C" or "VB" andhave the DLL handle the sturcture pointers differently?  If so, how would one code up C to fill in the VB structure?</p>