Solved

VB equivalent type for a C structure

Posted on 1998-09-18
1
207 Views
Last Modified: 2008-01-16
What is the correct vb type definition for the following C code and how do I call a fucntion expecting a pointer top such a structure?
/*****************************************************************************
      SeaDlg32.h

      Header file for Scanner Setup dialog boxes

      Copyright (c) 1995, Seaport Imaging
      Rex Miller
******************************************************************************/

#ifndef _SEADLG32_H
#define _SEADLG32_H

// option bits enable editing these features.
#define OPT_DOCSIZE            0x00000001
#define OPT_RES                  0x00000002
#define OPT_ORIENT            0x00000004
#define OPT_TIMEOUT            0x00000008
#define OPT_ENSIGNS            0x00000010
#define OPT_PAGEMODE      0x00000020
#define OPT_ADF                  0x00000040
#define OPT_PREFETCH      0x00000080
#define OPT_LEFTADJ            0x00000100
#define OPT_PAGELTH            0x00000200
#define OPT_MORE            0x00000400
#define OPT_ALL                  0x00FFFFFF      // All options editable.

#define OPT_BC_SYMBOLOGY  0x00000001
#define OPT_BC_CHECKSUM   0x00000002
#define OPT_BC_QUALITY    0x00000004
#define OPT_BC_FILTER     0x00000008
#define OPT_BC_SEARCH     0x00000010
#define OPT_BC_ORIENT     0x00000020
#define OPT_BC_WIDTH      0X00000040
#define OPT_BC_HEIGHT     0x00000080
#define OPT_BC_MAX_SYM    0x00000100
#define OPT_BC_MIN_SYM    0x00000200
#define OPT_BC_MIN_CHAR   0x00000400
#define OPT_BC_MIN_PARTIAL  0x00000800
#define OPT_BC_FIXED      0x00001000

#define OPT_MORE_DIALOG_ONLY    0x80000000 // Skips the main scanner dialog
#define OPT_OK_RESET            0x40000000 // Calls FcsResetScanner or sets Bar Code options after IDOK
#define OPT_INIT_FROM_REC       0x20000000 // Initializes dialog box from input record.

// Insure that records are packed on 4 byte boundaries. rdm
#pragma pack( push, publicrecords, 4 )
typedef struct of_scanrec {
      double Width;            // Page Width in inches
      double Height;            // Page Height in inches
      UINT Res;                  // Resolution
      UINT PageOrient;      // 0=portrait,1=landscape,2=fast portrait
      UINT NumBuffers;      // Number of page buffers
      UINT Timeout;            // Time in seconds
      UINT LengthChk;            // 0..100
      int LeftAdjust;            // -500..500
      PAGEMODE PageMode;      // 0=Simplex,1=Duplex
      PAGESIZE PageSize;      // 0=Letter etc
      BOOL Prefetch;            // T/F
      BOOL Ensigns;            // T/F
      BOOL AutoFeeder;      // T/F
} SCANREC;

typedef struct of_barcode {
      double      Width;                  // for FcsSetBarCodeMetrics
      double      Height;                  // for FcsSetBarCodeMetrics
      DWORD      Types;                  // for FcsSelectBarCodeTypes
      DWORD      Orientation;      // for FcsSetBarCodeMetrics
      DWORD      Quality;            // for FcsSetBarCodeMetrics
      DWORD      Small;                  // for FcsSetBarCodeSearchOrder
      DWORD      Medium;                  // for FcsSetBarCodeSearchOrder
      DWORD      Large;                  // for FcsSetBarCodeSearchOrder
      DWORD      MinNumber;            // Min # symbols to read. Not used by Autopilot.
      DWORD      Number;                  // Max # symbols to read. for FcsReadBarCodes
      DWORD      Length;                  // for FcsReadBarCodes
      DWORD      Fixed;                  // for FcsReadBarCodes
      DWORD      PartialLen;            // for FcsReadBarCodes
      DWORD      x;                        // Zone x & y coordinate
      DWORD      y;                        // Zone x & y coordinate
      DWORD      dx;                        // If DX & DY = 0 then no zoning is defined.
      DWORD      dy;
      BYTE      Options[64];      // for FcsSetBarCodeMetrics
} BARCODEREC;

typedef SCANREC *PSCANREC;
typedef BARCODEREC *PBARCODEREC;
#pragma pack( push, publicrecords, 4 )

extern __declspec(dllexport ) int __stdcall FcsScannerDialogBox( char* lpszName, char *lpszCaption, DWORD optBits, PSCANREC lpScanner, LPDWORD Result );
extern __declspec(dllexport ) int __stdcall FcsBarCodeDialogBox( DWORD optBits, BARCODEREC *lpBarCode );

#endif // _SEADLG32_H

 
The function to be called

int FcsScannerDialogBox( LPSTR name, LPSTR caption, DWORD options, SCANREC *params, LPDWORD result )
0
Comment
Question by:bbrennan2
1 Comment
 
LVL 2

Accepted Solution

by:
VBDesigns earned 50 total points
Comment Utility
Well, here's a crack at it.  Note that PAGEMODE and PAGESIZE are undefined, so you'll have to figure out what they are.  One way to verify the name of the exported functions is to right-click on the DLL from explorer and do a Quick View -- it will list exactly how they should be 'aliased'.  If I recall UINTs are Integers, and DOUBLEs are Longs.  Please feel free to correct me if I'm wrong.

When you get it working, simply call the DLL function just like you would a VB function:
lResult = FCSScannerDialogBox(sName, sCaption, lOptions, gtScanRec, lResult)

Good luck!

Option Explicit

' *****************************************************************************
' SeaDlg32.h
'
' Header file for Scanner Setup dialog boxes
'
' Copyright (c) 1995, Seaport Imaging
' Rex Miller
' ******************************************************************************/

' option bits enable editing these features.
Public Const OPT_DOCSIZE = &H1
Public Const OPT_RES = &H2
Public Const OPT_ORIENT = &H4
Public Const OPT_TIMEOUT = &H8
Public Const OPT_ENSIGNS = &H10
Public Const OPT_PAGEMODE = &H20
Public Const OPT_ADF = &H40
Public Const OPT_PREFETCH = &H80
Public Const OPT_LEFTADJ = &H100
Public Const OPT_PAGELTH = &H200
Public Const OPT_MORE = &H400
Public Const OPT_ALL = &HFFFFFF  ' All options editable.

Public Const OPT_BC_SYMBOLOGY = &H1
Public Const OPT_BC_CHECKSUM = &H2
Public Const OPT_BC_QUALITY = &H4
Public Const OPT_BC_FILTER = &H8
Public Const OPT_BC_SEARCH = &H10
Public Const OPT_BC_ORIENT = &H20
Public Const OPT_BC_WIDTH = &H40
Public Const OPT_BC_HEIGHT = &H80
Public Const OPT_BC_MAX_SYM = &H100
Public Const OPT_BC_MIN_SYM = &H200
Public Const OPT_BC_MIN_CHAR = &H400
Public Const OPT_BC_MIN_PARTIAL = &H800
Public Const OPT_BC_FIXED = &H1000

Public Const OPT_MORE_DIALOG_ONLY = &H80000000   ' Skips the main scanner dialog
Public Const OPT_OK_RESET = &H40000000           ' Calls FcsResetScanner or sets Bar Code options after IDOK
Public Const OPT_INIT_FROM_REC = &H20000000      ' Initializes dialog box from input record.

' Insure that records are packed on 4 byte boundaries. rdm
Public Type SCANREC
    Width As Long ' Page Width in inches
    Height As Long ' Page Height in inches
    Res As Integer ' Resolution
    PageOrient As Integer ' 0=portrait,1=landscape,2=fast portrait
    NumBuffers As Integer ' Number of page buffers
    Timeout As Integer ' Time in seconds
    LengthChk As Integer ' 0..100
    LeftAdjust As Integer ' -500..500
    ' ???? What is the PAGEMODE/SIZE?  Type?  Not defined here!
    'PAGEMODE PageMode; ' 0=Simplex,1=Duplex
    'PAGESIZE PageSize; ' 0=Letter etc
    ' MSVC6 BOOL is actually a VB LONG
    Prefetch As Long ' T/F
    Ensigns As Long ' T/F
    AutoFeeder As Long ' T/F
End Type

Public Type BARCODEREC
    Width As Long ' for FcsSetBarCodeMetrics
    Height As Long ' for FcsSetBarCodeMetrics
    Types As Long ' for FcsSelectBarCodeTypes
    Orientation As Long ' for FcsSetBarCodeMetrics
    Quality As Long ' for FcsSetBarCodeMetrics
    Small As Long ' for FcsSetBarCodeSearchOrder
    Medium As Long ' for FcsSetBarCodeSearchOrder
    Large As Long ' for FcsSetBarCodeSearchOrder
    MinNumber As Long ' Min # symbols to read. Not used by Autopilot.
    Number As Long ' Max # symbols to read. for FcsReadBarCodes
    Length As Long ' for FcsReadBarCodes
    Fixed As Long ' for FcsReadBarCodes
    PartialLen As Long ' for FcsReadBarCodes
    x As Long ' Zone x & y coordinate
    y As Long ' Zone x & y coordinate
    dx As Long ' If DX & DY = 0 then no zoning is defined.
    dy asLong
    ' NOTE -- I'm assuming the original C Options[64] means
    ' an array 64 in size, not 65.
    Options(63) As Byte
    'BYTE Options[64]; ' for FcsSetBarCodeMetrics
End Type

Public PSCANREC As SCANREC
Public PBARCODEREC As BARCODEREC

' Now here's where it can get tricky.  I'll include two declare types for these procedures
' since I'm not sure which one is 100% correct.  Don't forget to replace the libary name.

' Type 1
Declare Function FcsScannerDialogBox Lib "LIBRARYNAMEHERE" Alias "_FcsScannerDialogBox@20" ( _
 Byval Name As String, Byval Caption As String, ByVal optbits As Long, Scanner As SCANREC, Result As Long) As Long

' Type 2
Declare Function FcsScannerDialogBox Lib "LIBRARYNAMEHERE" ( _
 Byval Name As String, Byval Caption As String, ByVal optbits As Long, Scanner As SCANREC, Result As Long) As Long

' Type 1
Declare Function FcsBarCodeDialogBox Lib "LIBRARYNAMEHERE" Alias "_FcsScannerDialogBox@20" ( _
 ByVal optbits As Long, Barcode As BARCODEREC) As Long

' Type 2
Declare Function FcsBarCodeDialogBox Lib "LIBRARYNAMEHERE" ( _
 ByVal optbits As Long, Barcode As BARCODEREC) As Long


0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now