Is it possible to translate C Call to a DLL in Visual Basic?

G

Gillard

hello
I get a dll with standard call in C ++ but I really do not know how to use
it in VB

anyone can help???

there is the declarations in cpp to use the functions

#ifndef SFPDF_H
#define SFPDF_H

#pragma comment(lib, "SFPDF.lib")

typedef struct _SFPDFPOS {
DWORD dwX;
DWORD dwY;
DWORD dwW;
DWORD dwH;
DWORD dNewPage;
} SFPDFPOS, *LPSFPDFPOS;

DWORD __stdcall SFPDF_AddPage();
DWORD __stdcall SFPDF_Cell(double dwX, double dwY, double dwW, double dwH,
DWORD dwL, DWORD dwR, DWORD dwT, DWORD dwB, DWORD dwFill, DWORD dwAlign,
char *szTxt);
DWORD __stdcall SFPDF_DrawColor(DWORD dwR, DWORD dwG, DWORD dwB);
DWORD __stdcall SFPDF_DrawLine(DWORD dwX1, DWORD dwY1, DWORD dwX2, DWORD
dwY2);
DWORD __stdcall SFPDF_FillColor(DWORD dwR, DWORD dwG, DWORD dwB);
DWORD __stdcall SFPDF_GetHauteur();
DWORD __stdcall SFPDF_GetLargeur();
DWORD __stdcall SFPDF_Image(char *szFile, DWORD dwX, DWORD dwY, DWORD dwW,
DWORD dwH);
void __stdcall SFPDF_Init(DWORD dwOrientation);
DWORD __stdcall SFPDF_LineWidth(double dWidth);
DWORD __stdcall SFPDF_Output(char *szFile);
DWORD __stdcall SFPDF_SetFont(char *szPolice, DWORD dwSize);
void __stdcall SFPDF_SetFontSize(DWORD dwSize);
DWORD __stdcall SFPDF_Text(int dwX, int dwY, char *szTxt);
DWORD __stdcall SFPDF_TextColor(DWORD dwR, DWORD dwG, DWORD dwB);
DWORD __stdcall SFPDF_TextFlow(int dwX, int dwY, DWORD dwW, DWORD dwH, DWORD
dwAlign, char *szTxt);
void __stdcall SFPDF_SetBreakPageCallback(DWORD dwAddr);
double __stdcall SFPDF_GetLargeurTexte(char *szTxt);

#endif
 
L

Lloyd Sheen

Gillard said:
hello
I get a dll with standard call in C ++ but I really do not know how to use
it in VB

anyone can help???

there is the declarations in cpp to use the functions

#ifndef SFPDF_H
#define SFPDF_H

#pragma comment(lib, "SFPDF.lib")

typedef struct _SFPDFPOS {
DWORD dwX;
DWORD dwY;
DWORD dwW;
DWORD dwH;
DWORD dNewPage;
} SFPDFPOS, *LPSFPDFPOS;

DWORD __stdcall SFPDF_AddPage();
DWORD __stdcall SFPDF_Cell(double dwX, double dwY, double dwW, double dwH,
DWORD dwL, DWORD dwR, DWORD dwT, DWORD dwB, DWORD dwFill, DWORD dwAlign,
char *szTxt);
DWORD __stdcall SFPDF_DrawColor(DWORD dwR, DWORD dwG, DWORD dwB);
DWORD __stdcall SFPDF_DrawLine(DWORD dwX1, DWORD dwY1, DWORD dwX2, DWORD
dwY2);
DWORD __stdcall SFPDF_FillColor(DWORD dwR, DWORD dwG, DWORD dwB);
DWORD __stdcall SFPDF_GetHauteur();
DWORD __stdcall SFPDF_GetLargeur();
DWORD __stdcall SFPDF_Image(char *szFile, DWORD dwX, DWORD dwY, DWORD dwW,
DWORD dwH);
void __stdcall SFPDF_Init(DWORD dwOrientation);
DWORD __stdcall SFPDF_LineWidth(double dWidth);
DWORD __stdcall SFPDF_Output(char *szFile);
DWORD __stdcall SFPDF_SetFont(char *szPolice, DWORD dwSize);
void __stdcall SFPDF_SetFontSize(DWORD dwSize);
DWORD __stdcall SFPDF_Text(int dwX, int dwY, char *szTxt);
DWORD __stdcall SFPDF_TextColor(DWORD dwR, DWORD dwG, DWORD dwB);
DWORD __stdcall SFPDF_TextFlow(int dwX, int dwY, DWORD dwW, DWORD dwH,
DWORD dwAlign, char *szTxt);
void __stdcall SFPDF_SetBreakPageCallback(DWORD dwAddr);
double __stdcall SFPDF_GetLargeurTexte(char *szTxt);

#endif

To use the DLL use the following (as generated by the MS tool P/Invoke
Interop Assistant)
The following class can be used to access the DLL. Yous will have to change
the <Unknown> to your dll name so that it will use the correct DLL.

Hope it helps and the tool can be found at MS if you have further items to
use.

LS

Partial Public Class NativeConstants

'''SFPDF_H ->
'''Error generating expression: Value cannot be null.
'''Parameter name: node
Public Const SFPDF_H As String = ""
End Class

<System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)>
_
Public Structure SFPDFPOS

'''DWORD->unsigned int
Public dwX As UInteger

'''DWORD->unsigned int
Public dwY As UInteger

'''DWORD->unsigned int
Public dwW As UInteger

'''DWORD->unsigned int
Public dwH As UInteger

'''DWORD->unsigned int
Public dNewPage As UInteger
End Structure

Partial Public Class NativeMethods

'''Return Type: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_AddPage",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_AddPage() As UInteger
End Function

'''Return Type: DWORD->unsigned int
'''dwX: double
'''dwY: double
'''dwW: double
'''dwH: double
'''dwL: DWORD->unsigned int
'''dwR: DWORD->unsigned int
'''dwT: DWORD->unsigned int
'''dwB: DWORD->unsigned int
'''dwFill: DWORD->unsigned int
'''dwAlign: DWORD->unsigned int
'''szTxt: char*
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_Cell",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_Cell(ByVal dwX As Double, ByVal dwY As
Double, ByVal dwW As Double, ByVal dwH As Double, ByVal dwL As UInteger,
ByVal dwR As UInteger, ByVal dwT As UInteger, ByVal dwB As UInteger, ByVal
dwFill As UInteger, ByVal dwAlign As UInteger, ByVal szTxt As System.IntPtr)
As UInteger
End Function

'''Return Type: DWORD->unsigned int
'''dwR: DWORD->unsigned int
'''dwG: DWORD->unsigned int
'''dwB: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_DrawColor",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_DrawColor(ByVal dwR As UInteger, ByVal dwG
As UInteger, ByVal dwB As UInteger) As UInteger
End Function

'''Return Type: DWORD->unsigned int
'''dwX1: DWORD->unsigned int
'''dwY1: DWORD->unsigned int
'''dwX2: DWORD->unsigned int
'''dwY2: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_DrawLine",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_DrawLine(ByVal dwX1 As UInteger, ByVal dwY1
As UInteger, ByVal dwX2 As UInteger, ByVal dwY2 As UInteger) As UInteger
End Function

'''Return Type: DWORD->unsigned int
'''dwR: DWORD->unsigned int
'''dwG: DWORD->unsigned int
'''dwB: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_FillColor",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_FillColor(ByVal dwR As UInteger, ByVal dwG
As UInteger, ByVal dwB As UInteger) As UInteger
End Function

'''Return Type: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_GetHauteur",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_GetHauteur() As UInteger
End Function

'''Return Type: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_GetLargeur",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_GetLargeur() As UInteger
End Function

'''Return Type: DWORD->unsigned int
'''szFile: char*
'''dwX: DWORD->unsigned int
'''dwY: DWORD->unsigned int
'''dwW: DWORD->unsigned int
'''dwH: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_Image",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_Image(ByVal szFile As System.IntPtr, ByVal
dwX As UInteger, ByVal dwY As UInteger, ByVal dwW As UInteger, ByVal dwH As
UInteger) As UInteger
End Function

'''Return Type: void
'''dwOrientation: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_Init",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Sub SFPDF_Init(ByVal dwOrientation As UInteger)
End Sub

'''Return Type: DWORD->unsigned int
'''dWidth: double
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_LineWidth",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_LineWidth(ByVal dWidth As Double) As
UInteger
End Function

'''Return Type: DWORD->unsigned int
'''szFile: char*
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_Output",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_Output(ByVal szFile As System.IntPtr) As
UInteger
End Function

'''Return Type: DWORD->unsigned int
'''szPolice: char*
'''dwSize: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_SetFont",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_SetFont(ByVal szPolice As System.IntPtr,
ByVal dwSize As UInteger) As UInteger
End Function

'''Return Type: void
'''dwSize: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_SetFontSize",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Sub SFPDF_SetFontSize(ByVal dwSize As UInteger)
End Sub

'''Return Type: DWORD->unsigned int
'''dwX: int
'''dwY: int
'''szTxt: char*
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_Text",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_Text(ByVal dwX As Integer, ByVal dwY As
Integer, ByVal szTxt As System.IntPtr) As UInteger
End Function

'''Return Type: DWORD->unsigned int
'''dwR: DWORD->unsigned int
'''dwG: DWORD->unsigned int
'''dwB: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_TextColor",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_TextColor(ByVal dwR As UInteger, ByVal dwG
As UInteger, ByVal dwB As UInteger) As UInteger
End Function

'''Return Type: DWORD->unsigned int
'''dwX: int
'''dwY: int
'''dwW: DWORD->unsigned int
'''dwH: DWORD->unsigned int
'''dwAlign: DWORD->unsigned int
'''szTxt: char*
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_TextFlow",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_TextFlow(ByVal dwX As Integer, ByVal dwY As
Integer, ByVal dwW As UInteger, ByVal dwH As UInteger, ByVal dwAlign As
UInteger, ByVal szTxt As System.IntPtr) As UInteger
End Function

'''Return Type: void
'''dwAddr: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_SetBreakPageCallback",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Sub SFPDF_SetBreakPageCallback(ByVal dwAddr As UInteger)
End Sub

'''Return Type: double
'''szTxt: char*
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_GetLargeurTexte",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_GetLargeurTexte(ByVal szTxt As
System.IntPtr) As Double
End Function
End Class
 
G

Gillard

thank you but I am not shure I can use it

Lloyd Sheen said:
To use the DLL use the following (as generated by the MS tool P/Invoke
Interop Assistant)
The following class can be used to access the DLL. Yous will have to
change the <Unknown> to your dll name so that it will use the correct DLL.

Hope it helps and the tool can be found at MS if you have further items to
use.

LS

Partial Public Class NativeConstants

'''SFPDF_H ->
'''Error generating expression: Value cannot be null.
'''Parameter name: node
Public Const SFPDF_H As String = ""
End Class

<System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)>
_
Public Structure SFPDFPOS

'''DWORD->unsigned int
Public dwX As UInteger

'''DWORD->unsigned int
Public dwY As UInteger

'''DWORD->unsigned int
Public dwW As UInteger

'''DWORD->unsigned int
Public dwH As UInteger

'''DWORD->unsigned int
Public dNewPage As UInteger
End Structure

Partial Public Class NativeMethods

'''Return Type: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_AddPage",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_AddPage() As UInteger
End Function

'''Return Type: DWORD->unsigned int
'''dwX: double
'''dwY: double
'''dwW: double
'''dwH: double
'''dwL: DWORD->unsigned int
'''dwR: DWORD->unsigned int
'''dwT: DWORD->unsigned int
'''dwB: DWORD->unsigned int
'''dwFill: DWORD->unsigned int
'''dwAlign: DWORD->unsigned int
'''szTxt: char*
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_Cell",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_Cell(ByVal dwX As Double, ByVal dwY As
Double, ByVal dwW As Double, ByVal dwH As Double, ByVal dwL As UInteger,
ByVal dwR As UInteger, ByVal dwT As UInteger, ByVal dwB As UInteger, ByVal
dwFill As UInteger, ByVal dwAlign As UInteger, ByVal szTxt As
System.IntPtr) As UInteger
End Function

'''Return Type: DWORD->unsigned int
'''dwR: DWORD->unsigned int
'''dwG: DWORD->unsigned int
'''dwB: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_DrawColor",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_DrawColor(ByVal dwR As UInteger, ByVal dwG
As UInteger, ByVal dwB As UInteger) As UInteger
End Function

'''Return Type: DWORD->unsigned int
'''dwX1: DWORD->unsigned int
'''dwY1: DWORD->unsigned int
'''dwX2: DWORD->unsigned int
'''dwY2: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_DrawLine",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_DrawLine(ByVal dwX1 As UInteger, ByVal
dwY1 As UInteger, ByVal dwX2 As UInteger, ByVal dwY2 As UInteger) As
UInteger
End Function

'''Return Type: DWORD->unsigned int
'''dwR: DWORD->unsigned int
'''dwG: DWORD->unsigned int
'''dwB: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_FillColor",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_FillColor(ByVal dwR As UInteger, ByVal dwG
As UInteger, ByVal dwB As UInteger) As UInteger
End Function

'''Return Type: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_GetHauteur",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_GetHauteur() As UInteger
End Function

'''Return Type: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_GetLargeur",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_GetLargeur() As UInteger
End Function

'''Return Type: DWORD->unsigned int
'''szFile: char*
'''dwX: DWORD->unsigned int
'''dwY: DWORD->unsigned int
'''dwW: DWORD->unsigned int
'''dwH: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_Image",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_Image(ByVal szFile As System.IntPtr, ByVal
dwX As UInteger, ByVal dwY As UInteger, ByVal dwW As UInteger, ByVal dwH
As UInteger) As UInteger
End Function

'''Return Type: void
'''dwOrientation: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_Init",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Sub SFPDF_Init(ByVal dwOrientation As UInteger)
End Sub

'''Return Type: DWORD->unsigned int
'''dWidth: double
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_LineWidth",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_LineWidth(ByVal dWidth As Double) As
UInteger
End Function

'''Return Type: DWORD->unsigned int
'''szFile: char*
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_Output",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_Output(ByVal szFile As System.IntPtr) As
UInteger
End Function

'''Return Type: DWORD->unsigned int
'''szPolice: char*
'''dwSize: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_SetFont",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_SetFont(ByVal szPolice As System.IntPtr,
ByVal dwSize As UInteger) As UInteger
End Function

'''Return Type: void
'''dwSize: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_SetFontSize",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Sub SFPDF_SetFontSize(ByVal dwSize As UInteger)
End Sub

'''Return Type: DWORD->unsigned int
'''dwX: int
'''dwY: int
'''szTxt: char*
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_Text",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_Text(ByVal dwX As Integer, ByVal dwY As
Integer, ByVal szTxt As System.IntPtr) As UInteger
End Function

'''Return Type: DWORD->unsigned int
'''dwR: DWORD->unsigned int
'''dwG: DWORD->unsigned int
'''dwB: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_TextColor",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_TextColor(ByVal dwR As UInteger, ByVal dwG
As UInteger, ByVal dwB As UInteger) As UInteger
End Function

'''Return Type: DWORD->unsigned int
'''dwX: int
'''dwY: int
'''dwW: DWORD->unsigned int
'''dwH: DWORD->unsigned int
'''dwAlign: DWORD->unsigned int
'''szTxt: char*
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_TextFlow",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_TextFlow(ByVal dwX As Integer, ByVal dwY
As Integer, ByVal dwW As UInteger, ByVal dwH As UInteger, ByVal dwAlign As
UInteger, ByVal szTxt As System.IntPtr) As UInteger
End Function

'''Return Type: void
'''dwAddr: DWORD->unsigned int
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_SetBreakPageCallback",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Sub SFPDF_SetBreakPageCallback(ByVal dwAddr As UInteger)
End Sub

'''Return Type: double
'''szTxt: char*
<System.Runtime.InteropServices.DllImportAttribute("<Unknown>",
EntryPoint:="SFPDF_GetLargeurTexte",
CallingConvention:=System.Runtime.InteropServices.CallingConvention.StdCall)>
_
Public Shared Function SFPDF_GetLargeurTexte(ByVal szTxt As
System.IntPtr) As Double
End Function
End Class
 
Top