Passing a structure to a C dll in VB .NET

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Steve Turner (anonymous_at_discussions.microsoft.com)
Date: 02/05/04


Date: Thu, 5 Feb 2004 15:41:08 -0800

I have read several interesting posts on passing structures to C dlls, but none seem to cover the following case. The structure (as seen in C) is as follows:

typedef struct tag_scanparm
{
  short cmd;
  short fdc;
  WORD dsf;
  short boxcar;
  short average;
  short chan_ena[\4];
  short scan_dark;
  short correct_dark;
  short extrig;
  short upper4chan;
  float sdat[\4][\2048]
} SCANPARM;

The real problem seems to be with the arrays. Even using attributes and specifying a size when I decalre the structure in VB, I can't get this to work. It has to be passed by reference, and when I call "GetType" as a part of my call to Marshall.StructureToPtr, I get an error message to the effect that my structure cannot be marshalled as an unmanaged type.

Please forgive the fact that I don't have the exact error message handy...I tried getting this to work for about a day, scanning all types of message boards, and finally threw in the towel and created a COM object in C++ that wrapped the calls to this 3rd Party dll. That's OK for me, but for some of our customers who use VB exclusively it would be nice to know how to do this directly from VB...there has to be a way, and I think I was close!

Any help would be greatly appreciated!

Thanks,

Steve



Relevant Pages

  • Re: Operator new failing in windows after several days of operation
    ... More info/answering questions from other posts: ... All DLLs link to the Multithreadded DLL runtime in the compiler ... what are the compiler and linker settings for the DLLs? ...
    (microsoft.public.vc.language)
  • Re: Overview
    ... You claimed that DLLS were a universal feature. ... the only reason you are not in my killfile is ... _specifically_ so that I can read your posts and point out any errors ...
    (comp.lang.c)
  • Re: [Xnews] Formatted Font
    ... Or am I missing something obvious? ... you didn't show us the versions of the DLLs. ... know where it's getting its copy of RICHED32. ... Killing all posts from Google Groups ...
    (news.software.readers)
  • RE: Where is CryptExportPKCS8Ex() ?
    ... I have tried strings.exe from sysinternals to search all the dlls in ... When responding to posts, please "Reply to Group" via your newsreader so ...
    (microsoft.public.platformsdk.security)