[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Convert C header declarations to VB module declarations

Posted on 1999-10-25
10
Medium Priority
?
482 Views
Last Modified: 2008-03-10
I am looking for anyone who has sufficient knowlege of both C and VB to take a C header file with DLL calling declarations in it and convert it to a VB module with the same declarations to allow calling the DLL functions.
I can provide the C sample calling code and header file.
Please contact me on phil@watin.com.au if you are interested and I will send the C files.
Phil
0
Comment
Question by:watin
10 Comments
 
LVL 4

Expert Comment

by:nil_dib
ID: 2158060
/* header */
extern "C" __declspec(dllexport) int maxFunc( int n1, int n2 );


/* c */
#include "MyFunctions.h"

int maxFunc( int n1, int n2 )
{
    return (n1 > n2) ? n1 : n2;
}

'VB:
Public Declare Function maxFunc Lib "C:\mydll" (ByVal n1 As Integer, ByVal n2 As Integer) As Integer
....

Sub Test()
    Dim x, y
    Dim res
    x = 123..
    y = ....
    'call dll function
    res = maxFunc(x,y)
End Sub


nil_dib


0
 

Author Comment

by:watin
ID: 2158107
The above code seems to be an example of how a declaration and call are made in both C and VB.
Unfortunately I already have numerous of these but actually require a number of complex calls rewritten in VB.
If the writer wants to rewrite them for me I will send them and pay what is required but I have not so far been successful in trying to do so myself and I have no time left to keep trying.
phil@watin.com.au
0
 
LVL 3

Expert Comment

by:MDarling
ID: 2158269
post your header

Also - before you start - are the
C functions defined with the standard
call mechanism (ie pascal calling convention)? - if not you cant call
them from VB.

In that cas you would have to write a wrapper DLL which exports standard call
versions of the ones in your DLL and
internally loads and calls the 1st DLL.

regards,
mike.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:watin
ID: 2158390
OK the header follows.
I don't know enough about calling conventions so answer your question above. Maybe you can tell by looking at it. If it needs a wrapper app then OK that's what I need. But however I need it urgently !

/*****************************************************************************
* DSDLL.H
*
* Description: Contains the function prototypes for the exported API's
*
******************************************************************************/
#include "prodrec.h"

//ActualCommand codes
#define nREAD_CELL                              1
#define nWRITE_CELL                              2
#define nCHECK_ALGO_STATUS                  6
#define nCHECK_COUNTER_STATUS            7
#define nACTIVATE_ALGO_PART1            8
#define nACTIVATE_ALGO_PART2            9
#define nDECREMENT_CELL                        10
#define nACTIVATE_PRODUCT                  11
#define nRESET_OR_ADD_DIST_COUNTER      12
#define nINCREMENT_COUNTER                  13

typedef struct _CELL_DATA {
short cellAddr;
short cellValue;
} CELL_DATA;

typedef struct _COMMANDSREC {
  short CommandIndex;
  short ActualCommand;
  short CellIndex;
  short ValIndex;
  short ACIndex;
 } COMMANDREC;

typedef struct _SAFECOMMANDREC {
      short ActualCommand;
      short CellIndex;
      short ValIndex;
      short ACIndex;
      char prod_name[16];
 } SAFECOMMANDREC;       

 typedef struct _RESULTREC {
  short CellIndex;
  short ValIndex;
  short ACIndex;
 } RESULTREC;                              

unsigned long RbRtlShlDword( unsigned long theData, unsigned short cnt );
unsigned long RbRtlShrDword( unsigned long theData, unsigned short cnt );
unsigned short FindKeyPosition(int *u_key, int *d_key);

/**************************************************************************
* Prototypes for exported API's
***************************************************************************/

extern "C" short __declspec(dllexport) WINAPI SAFEInitGlobal(unsigned char*);

extern "C" unsigned short __declspec(dllexport) WINAPI DecodeKeyID(unsigned char*,
                                                          char*,
                                                          RESULTREC*,
                                                          unsigned short*);  

extern "C" unsigned short __declspec(dllexport) WINAPI GenerateUpdateStr( unsigned char * GlobPtr,
                                                      SAFECOMMANDREC     *safe_commands,
                                                                          short             count,
                                                                          char           *updateStr,
                                                                          PROD_LIST  *prod_list_ptr);  
extern "C" unsigned short __declspec(dllexport) WINAPI ReadWizardDATFile(char*,
                                                                                                PROD_LIST_PTR);
0
 

Author Comment

by:watin
ID: 2158393
Following is also the second header called by the first.

#ifndef __PRODREC__
#define __PRODREC__

//defines for activation types
#define STATIC 0
#define TRUSTED 1
#define DISTRIBUTED 2
#define DROP_IN 3
#define ACTIVE 4

#define MAX_PRODS 14
typedef unsigned short int WORD;

#pragma pack(1)
typedef struct {
      char cell_address;
      char product_id;
      char prod_name[17];
      WORD model;
      WORD algo1;
      WORD algo2;
      WORD password1;
      WORD password2;
}PRODUCT_REC;

typedef struct {
      PRODUCT_REC prod_list[MAX_PRODS];
} PROD_LIST, *PROD_LIST_PTR;

#endif
0
 
LVL 3

Expert Comment

by:MDarling
ID: 2158552
WINAPI indicates pascal calling convention - so your ok there.

going to be some time before i can look at this - seeing as im at work.

but for now try this...

Private Declare Function SAFEInitGlobal Lib "YourDLL.DLL" (ByVal s As String) As Integer

if you can get this to work you're on your way.

regards,
mike.
0
 
LVL 3

Expert Comment

by:MDarling
ID: 2158561
another quick question

can you look at the exports of your DLL
(use quickview) and tell me what they
look like, i.e do they have any name
decoration.

for example

is the exported name

SAFEInitGlobal

or is it

_SAFEInitGlobal@4

or something similar

regards,
mike.
0
 

Author Comment

by:watin
ID: 2158587
Sorry Mike I don't even know what Quickview is or what you mean by "exports" from DLLs.

I have called numerous DLLs before using declarations similar to the one you suggest above.
That is not the problem.
It is the definition of the variables and structs/types passed by these calls and how they are written correctly in the declarations so they work.
Phil
0
 
LVL 3

Expert Comment

by:MDarling
ID: 2158620
quickview comes with windows
its an accessory which isnt installed by default - you can install it by
add remove programs/windows setup.

if you right click a dll you should get it as an option.

it is crucial to know the exports as VB
uses them to gain entry points into the
DLL.

regards,
mike.
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 400 total points
ID: 2188112
Next is coversion of you 1-st file
(second: same)


Private Type CELL_DATA
  cellAddr as Integer
  cellValue as Integer
End type

Private Type COMMANDSREC
  CommandIndex as Integer
  ActualCommand as Integer
  CellIndex as Integer
  ValIndex as Integer
  ACIndex as Integer
End Type

Private Type SAFECOMMANDREC
 ActualCommand as Integer
 CellIndex as Integer
 ValIndex as Integer
 ACIndex as Integer
 prod_name as String*16
End Type

Private Type RESULTREC
  CellIndex as Integer
  short as Integer
  short as Integer
End Type
Prived Function RbRtlShlDword (theData as Long,cnt as Integer) as Long
' you code
End Function
Prived Function RbRtlShlDword( theData as Long,  cnt as Integer) as Long
' you code
End Function

Prived Function FindKeyPosition(u_key as Long , d_key as Long) as Integer
' you code
End Function

'***************************************************************************/
Private Declare Function SAFEInitGlobal Lib "mylib.dll" Alias "real_name" (str as String) as Integer

Private Declare Function DecodeKeyID Iib "mylib.dll" Alias "real_name" (str as String, _
   str1 as String,result as RESULTREC,us as Integer) as Integer

Private Declare Function GenerateUpdateStr Lib "mylib.dll" Alias "real_name" _
     (  GlobPtr as String,safe_commands as SAFECOMMANDREC, _
              count as String,
              updateStr as String, _
              prod_list_ptr as PROD_LIST) as  Integer
Private Declare Function  ReadWizardDATFile Lib "mylib.dll" Alias "real_name" _
 (str as String,prod_list_ptr  LIST_PTR) as Integer
Best Regards, Alex
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

612 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