Solved

Cannot access function in C DLL with VB

Posted on 2003-11-20
3
252 Views
Last Modified: 2010-05-03
Hi,

I'am having difficulties in VB with the use of a function call in a certain C DLL.

The DLL function is described below. There is a struct in it aswell.
Hopefully you have an answer to this. I tried a lot but nothing will work.

int IOTSVC_API iotsvc_Open(unsigned long *pulHandle, char *csTarget, iotlayout_t *pLayout);

typedef struct
{
  unsigned char ucType;
  char    csName[16];
  unsigned short  usTotalNoInputs;
  unsigned short  usNoAnalogeInputs;
  unsigned short  usNoDigitalInputs;
  unsigned short  usTotalNoOutputs;
  unsigned short  usNoAnalogeOutputs;
  unsigned short  usNoDigitalOutputs;
} iotmodule_t;

typedef struct
{
  unsigned short  usTotalNoInputs;
  unsigned short  usTotalNoOutputs;
  unsigned short  usNoIOmodules;
  iotmodule_t IOmoduleInfo[MAX_NO_IO_MODULES];
} iotlayout_t;

How should i declare this in VB and how can i access the C function in VB.

Thank for your help

AVI
0
Comment
Question by:AVsystem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Accepted Solution

by:
sudhakar_koundinya earned 50 total points
ID: 9795102

Type iotmodule_t
    ucType As Byte
    csName As String
    usTotalNoInputs  As Byte
    usNoAnalogeInputs As Byte
    usNoDigitalInputs As Byte
    usTotalNoOutputs As Byte
    usNoAnalogeOutputs As Byte
    usNoDigitalOutputs As Byte
End Type

Type iotlayout_t

  usTotalNoInputs As Byte
  usTotalNoOutputs As Byte
  usNoIOmodules As Byte
  IOmoduleInfo As iotmodule_t
End Type



Public Declare Function iotsvc_Open(byref pulHandle as byte, byref csTarget as string ,  byref pLayout as iotlayout_t)as integer


is this stuff is helpful to you

some minor changes may be required in that. I haven't put exactly same as your structures as i am in hurry now
0
 
LVL 7

Expert Comment

by:Smallint
ID: 9795511
Hi AVsystem,

C function must be defined with _stdcall

Take a look here, may is helpful for you

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20608530.html

Cheers

0
 

Author Comment

by:AVsystem
ID: 9809577
Hi, AVsystem here,

It still wo'nt work.

Probably the data definitions are not mapped from C to VB.
There is defined an unsigned long, unsigned short and a unsigned char.
Is there someone that has enough expierience to tackle this for me.

Greetings AVI
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

690 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