Thread: Passing UDTs from VBA to C DLL

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    6

    Passing user-defined types from VBA to C DLL

    I am writing a DLL in C to replace some functions in an Excel VBA module. I have replaced many of these successfully but have now reached the point where I need to pass user-defined types (UDT) to the DLL as function parameters.

    The simplest of the UDTs has 14 elements all of type 'single', none of which are arrays. The most complex has 52 singles, 2 doubles, 2 arrays of variable-length strings and one variant (yes, I know, but it's someone else's code and I'm stuck with it).

    Starting with the simpler one I set up a 'typedef struct' arrangement in C that has 14 elements of type 'float'. I created a test function that took one of these structs as its parameter. In VBA I called the function, passing the UDT variable ByRef.

    Debug mode showed that the values that the C function received were not the values that the original UDT variable contained.

    Could anyone point out where I am going wrong? I haven't been able to find anything that explains how to do this, probably because I couldn't find a decent way to phrase the question in Google. I did find some resources that indicate I may have to use something called SAFEARRAY, but the documentation I can find for this assumes more knowledge than I have (this DLL is my first Windows project).

    A 'here's how to do it' answer would be great, but so would a 'here's where to look it up' one!

    Thanks

    Neil Matthews
    Last edited by Nelviticus; 06-12-2003 at 02:28 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing .Net Bitmap to C++ Dll
    By xJJx in forum C++ Programming
    Replies: 4
    Last Post: 01-30-2009, 05:16 AM
  2. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  3. Passing an Array of Strings from VB to a C DLL
    By mr_nice! in forum Windows Programming
    Replies: 9
    Last Post: 03-08-2005, 06:16 AM
  4. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 12:34 PM
  5. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM