一样在VB中定义结构,例如 Const CCDEVICENAME = 32 Const CCFORMNAME = 32 Const DM_PELSWIDTH = &H80000 Const DM_PELSHEIGHT = &H100000 Const CDS_TEST = &H4 Private Type DISPLAY_DEVICE cb As Long DeviceName As String * 32 DeviceString As String * 128 StateFlags As Long DeviceID As String * 128 DeviceKey As String * 128 End Type Private Type DEVMODE dmDeviceName As String * CCDEVICENAME dmSpecVersion As Integer dmDriverVersion As Integer dmSize As Integer dmDriverExtra As Integer dmFields As Long dmOrientation As Integer dmPaperSize As Integer dmPaperLength As Integer dmPaperWidth As Integer dmScale As Integer dmCopies As Integer dmDefaultSource As Integer dmPrintQuality As Integer dmColor As Integer dmDuplex As Integer dmYResolution As Integer dmTTOption As Integer dmCollate As Integer dmFormName As String * CCFORMNAME dmUnusedPadding As Integer dmBitsPerPel As Integer dmPelsWidth As Long dmPelsHeight As Long dmDisplayFlags As Long dmDisplayFrequency As Long dmICMMethod As Long 'NT 4.0 dmICMIntent As Long 'NT 4.0 dmMediaType As Long 'NT 4.0 dmDitherType As Long 'NT 4.0 dmReserved1 As Long 'NT 4.0 dmReserved2 As Long 'NT 4.0 dmPanningWidth As Long 'Win2000 dmPanningHeight As Long 'Win2000 End Type Private Declare Function ChangeDisplaySettingsEx Lib "user32" Alias "ChangeDisplaySettingsExA" (lpszDeviceName As Any, lpDevMode As Any, ByVal hWnd As Long, ByVal dwFlags As Long, lParam As Any) As Long Private Declare Function EnumDisplayDevices Lib "user32" Alias "EnumDisplayDevicesA" (Unused As Any, ByVal iDevNum As Long, lpDisplayDevice As DISPLAY_DEVICE, ByVal dwFlags As Long) As Boolean Dim OldX As Long, OldY As Long, T As Long Private Sub Form_Load() 'KPD-Team 2000 'URL: http://www.allapi.net/ 'E-Mail: [email protected] Dim DD As DISPLAY_DEVICE, DevM As DEVMODE DD.cb = Len(DD) OldX = Screen.Width / Screen.TwipsPerPixelX OldY = Screen.Height / Screen.TwipsPerPixelY 'First retieve some display info If EnumDisplayDevices(ByVal 0&, 0, DD, ByVal 0&) Then 'and show it Me.AutoRedraw = True Me.Print "Device String:" + Left$(DD.DeviceString, InStr(1, DD.DeviceString, Chr$(0)) - 1) Me.Print "Device Name:" + Left$(DD.DeviceName, InStr(1, DD.DeviceName, Chr$(0)) - 1) Me.Print "Device Key:" + Left$(DD.DeviceKey, InStr(1, DD.DeviceKey, Chr$(0)) - 1) Me.Print "Device ID:" + Left$(DD.DeviceID, InStr(1, DD.DeviceID, Chr$(0)) - 1) Else Me.Print "Error while retrieving Display Information" End If DevM.dmSize = Len(DevM) 'we want to change the horizontal and the vertical resolution DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT DevM.dmPelsWidth = 640 DevM.dmPelsHeight = 480 'change the display settings Call ChangeDisplaySettingsEx(ByVal 0&, DevM, ByVal 0&, CDS_TEST, ByVal 0&) T = Timer Do: DoEvents: Loop Until Timer > T + 5 DevM.dmPelsWidth = OldX DevM.dmPelsHeight = OldY 'change the display settings back to the old settings Call ChangeDisplaySettingsEx(ByVal 0&, DevM, ByVal 0&, CDS_TEST, ByVal 0&) End Sub
C代码:#ifndef _FILLPOS_H #define _FILLPOS_H#ifdef FILLPOS_EXPORTS #define FILLPOS_API __declspec(dllexport) #else #define FILLPOS_API __declspec(dllimport) #endif#ifdef __cplusplus extern "C" { #endiftypedef struct _ID_125K { char id[2+1]; char no[8+1]; }ID_125K;typedef struct _FillData { char operate[20+1]; char cardtype; char stypename[20+1]; char serialno[8+1]; char cardno[10+1]; char makedate[8+1]; char fillmodeint; char fillmode[20+1]; int fillmoney; int realmoney; int cardoldmoney; int cardmoney; char deptno[8+1]; char termid[16+1]; char termserialno[16+1]; char operno[8+1]; char sdatetime[14+1]; char sak; char appserialno[16+1]; }FillData;typedef struct _SellData { char operate[20+1]; char cardtype; char stypename[20+1]; char serialno[8+1]; char cardno[10+1]; char makedate[8+1]; int deposit; char deptno[8+1]; char termid[16+1]; char termserialno[16+1]; char operno[8+1]; char sdatetime[14+1]; char sak; char appserialno[16+1]; }SellData; *********************这个是别人给的dll,就是下面这个地方有点不懂 ,这个回调函数回调的就是 一个结构体呀,但老是提示内存错误***************************************** typedef void (CALLBACK* FillCallBack)(FillData fillData); typedef void (CALLBACK* SellCallBack)(SellData sellData); FILLPOS_API int __stdcall IcFill(int xpos, int ypos, FillCallBack lpFillCallBack, SellCallBack lpSellCallBack); #ifdef __cplusplus } #endif#endif麻烦帮忙看看是否是定义有问题,非常感谢! VB里的定义: Declare Function IcFill Lib "FillPos.dll" (ByVal xpos As Integer, _ ByVal ypos As Integer, _ ByRef FillCallBack As FillData, _ ByRef SellCallback As SellData) As Integer Public Type FillData operate(20) As Byte cardtype As Byte stypename(20) As Byte serialno(8) As Byte cardno(10) As Byte makedate(8) As Byte fillmodeint As Byte fillmode(20) As Byte
fillmoney As Long realmoney As Long cardoldmoney As Long cardmoney As Long
deptno(8) As Byte termid(16) As Byte termserialno(16) As Byte operno(8) As Byte sdatetime(14) As Byte sak As Byte appserialno(16) As Byte End TypePublic Type SellData operate As Byte cardtype As Byte stypename(20) As Byte serialno(8) As Byte cardno(10) As Byte makedate(8) As Byte deposit As Long deptno(8) As Byte termid(16) As Byte termserialno(16) As Byte operno(8) As Byte sdatetime(14) As Byte sak As Byte appserialno(16) As Byte End Type
Declare Function IcFill Lib "FillPos.dll" (ByVal xpos As Long, _ ByVal ypos As Long, _ ByVal FillCallBack As Long, _ ByVal SellCallback As Long _ ) As Long 这是两个函数指针啊!!! 你装个 API-Guide 参考下 EnumWindows 的用法吧。
Const CCDEVICENAME = 32
Const CCFORMNAME = 32
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const CDS_TEST = &H4
Private Type DISPLAY_DEVICE
cb As Long
DeviceName As String * 32
DeviceString As String * 128
StateFlags As Long
DeviceID As String * 128
DeviceKey As String * 128
End Type
Private Type DEVMODE
dmDeviceName As String * CCDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmOrientation As Integer
dmPaperSize As Integer
dmPaperLength As Integer
dmPaperWidth As Integer
dmScale As Integer
dmCopies As Integer
dmDefaultSource As Integer
dmPrintQuality As Integer
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCFORMNAME
dmUnusedPadding As Integer
dmBitsPerPel As Integer
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
dmICMMethod As Long 'NT 4.0
dmICMIntent As Long 'NT 4.0
dmMediaType As Long 'NT 4.0
dmDitherType As Long 'NT 4.0
dmReserved1 As Long 'NT 4.0
dmReserved2 As Long 'NT 4.0
dmPanningWidth As Long 'Win2000
dmPanningHeight As Long 'Win2000
End Type
Private Declare Function ChangeDisplaySettingsEx Lib "user32" Alias "ChangeDisplaySettingsExA" (lpszDeviceName As Any, lpDevMode As Any, ByVal hWnd As Long, ByVal dwFlags As Long, lParam As Any) As Long
Private Declare Function EnumDisplayDevices Lib "user32" Alias "EnumDisplayDevicesA" (Unused As Any, ByVal iDevNum As Long, lpDisplayDevice As DISPLAY_DEVICE, ByVal dwFlags As Long) As Boolean
Dim OldX As Long, OldY As Long, T As Long
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim DD As DISPLAY_DEVICE, DevM As DEVMODE
DD.cb = Len(DD)
OldX = Screen.Width / Screen.TwipsPerPixelX
OldY = Screen.Height / Screen.TwipsPerPixelY
'First retieve some display info
If EnumDisplayDevices(ByVal 0&, 0, DD, ByVal 0&) Then
'and show it
Me.AutoRedraw = True
Me.Print "Device String:" + Left$(DD.DeviceString, InStr(1, DD.DeviceString, Chr$(0)) - 1)
Me.Print "Device Name:" + Left$(DD.DeviceName, InStr(1, DD.DeviceName, Chr$(0)) - 1)
Me.Print "Device Key:" + Left$(DD.DeviceKey, InStr(1, DD.DeviceKey, Chr$(0)) - 1)
Me.Print "Device ID:" + Left$(DD.DeviceID, InStr(1, DD.DeviceID, Chr$(0)) - 1)
Else
Me.Print "Error while retrieving Display Information"
End If
DevM.dmSize = Len(DevM)
'we want to change the horizontal and the vertical resolution
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
DevM.dmPelsWidth = 640
DevM.dmPelsHeight = 480
'change the display settings
Call ChangeDisplaySettingsEx(ByVal 0&, DevM, ByVal 0&, CDS_TEST, ByVal 0&)
T = Timer
Do: DoEvents: Loop Until Timer > T + 5
DevM.dmPelsWidth = OldX
DevM.dmPelsHeight = OldY
'change the display settings back to the old settings
Call ChangeDisplaySettingsEx(ByVal 0&, DevM, ByVal 0&, CDS_TEST, ByVal 0&)
End Sub
#define _FILLPOS_H#ifdef FILLPOS_EXPORTS
#define FILLPOS_API __declspec(dllexport)
#else
#define FILLPOS_API __declspec(dllimport)
#endif#ifdef __cplusplus
extern "C" {
#endiftypedef struct _ID_125K
{
char id[2+1];
char no[8+1];
}ID_125K;typedef struct _FillData
{
char operate[20+1]; char cardtype;
char stypename[20+1];
char serialno[8+1];
char cardno[10+1];
char makedate[8+1]; char fillmodeint;
char fillmode[20+1]; int fillmoney;
int realmoney;
int cardoldmoney;
int cardmoney; char deptno[8+1];
char termid[16+1];
char termserialno[16+1];
char operno[8+1];
char sdatetime[14+1]; char sak;
char appserialno[16+1];
}FillData;typedef struct _SellData
{
char operate[20+1]; char cardtype;
char stypename[20+1];
char serialno[8+1];
char cardno[10+1];
char makedate[8+1]; int deposit; char deptno[8+1];
char termid[16+1];
char termserialno[16+1];
char operno[8+1];
char sdatetime[14+1]; char sak;
char appserialno[16+1];
}SellData;
*********************这个是别人给的dll,就是下面这个地方有点不懂 ,这个回调函数回调的就是
一个结构体呀,但老是提示内存错误*****************************************
typedef void (CALLBACK* FillCallBack)(FillData fillData);
typedef void (CALLBACK* SellCallBack)(SellData sellData);
FILLPOS_API int __stdcall IcFill(int xpos, int ypos, FillCallBack lpFillCallBack, SellCallBack lpSellCallBack);
#ifdef __cplusplus
}
#endif#endif麻烦帮忙看看是否是定义有问题,非常感谢!
VB里的定义:
Declare Function IcFill Lib "FillPos.dll" (ByVal xpos As Integer, _
ByVal ypos As Integer, _
ByRef FillCallBack As FillData, _
ByRef SellCallback As SellData) As Integer
Public Type FillData
operate(20) As Byte
cardtype As Byte
stypename(20) As Byte
serialno(8) As Byte
cardno(10) As Byte
makedate(8) As Byte
fillmodeint As Byte
fillmode(20) As Byte
fillmoney As Long
realmoney As Long
cardoldmoney As Long
cardmoney As Long
deptno(8) As Byte
termid(16) As Byte
termserialno(16) As Byte
operno(8) As Byte
sdatetime(14) As Byte
sak As Byte
appserialno(16) As Byte
End TypePublic Type SellData
operate As Byte
cardtype As Byte
stypename(20) As Byte
serialno(8) As Byte
cardno(10) As Byte
makedate(8) As Byte
deposit As Long
deptno(8) As Byte
termid(16) As Byte
termserialno(16) As Byte
operno(8) As Byte
sdatetime(14) As Byte
sak As Byte
appserialno(16) As Byte
End Type
ByVal ypos As Long, _
ByVal FillCallBack As Long, _
ByVal SellCallback As Long _
) As Long
这是两个函数指针啊!!!
你装个 API-Guide 参考下 EnumWindows 的用法吧。