extern "C" __declspec(dllexport) int __stdcall FileTypeA( char **argv );........ //我的函数
int __stdcall FileTypeA(char **argv )
{
char strFileInfo[0x200];
CFI aFi;
memset(strFileInfo, 0, sizeof(strFileInfo));
// 判断类型
aFi.FI(argv[1], strFileInfo);
return strFileInfo;
//这个是个地址如C:\windows\explorer.exe
}
请问如何把strFileInfo传替给FileTypeA,并在vb6里面获得FileTypeA返回值,
int __stdcall FileTypeA(char **argv )
{
char strFileInfo[0x200];
CFI aFi;
memset(strFileInfo, 0, sizeof(strFileInfo));
// 判断类型
aFi.FI(argv[1], strFileInfo);
return strFileInfo;
//这个是个地址如C:\windows\explorer.exe
}
请问如何把strFileInfo传替给FileTypeA,并在vb6里面获得FileTypeA返回值,
在vb声明FileTypeA的时候,用ByRef strFileInfo as String
调用FileTypeA后,把strFileInfo拿出来用
指针得用ByRef
////////////////////////
// MyDLL.c
////////////////////////#include "Windows.h"
//#include "MyDll.h"////////////////////////
// DllMain
int APIENTRY DllMain(HANDLE hInst,DWORD ul_reason_being_called,LPVOID lpReserved)
{
return 1;
UNREFERENCED_PARAMETER(hInst);
UNREFERENCED_PARAMETER(ul_reason_being_called);
UNREFERENCED_PARAMETER(lpReserved);
}////////////////////////
// Myfuncionint APIENTRY MyFunction(int x,int y,int * z)
{
*z=100;
MessageBox(NULL,"hello","e",MB_OK);
x=100;
return (x+y);
}/*extern "C"
{
int APIENTRY MyFunction(int x,int y);
}
*/
////////////////////////
// MyDLL.def
////////////////////////
LIBRARY MyDLLCODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD SINGLEEXPORTS
;Function name
MyFunction Private Declare Function MyFunction Lib "MyDll.dll" (ByVal x As Integer, ByVal y As Integer, ByRef z As Integer) As Integer
Private Sub Command1_Click()
Dim x, y, z, ret As Integer
x = 10
y = 10
z = 10
ret = MyFunction(x, y, z)
MsgBox "x=" + CStr(x)
MsgBox "z=" + CStr(z)
End Sub
能够猜测出结果吗?我调试过,x=10,z=100,老马也不好好看看还让别人试,不过试下也好,理不辩不明
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal pDest As Any, ByVal pSrc As Any, ByVal ByteLen As Long)
Private Sub Command1_Click()
Dim s1 As String, s2 As String
s1 = "asdf"
s2 = Space(255)
CopyMemory VarPtr(s2), VarPtr(s1), Len(s1)
Debug.Print s2
End SubOption Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSrc As Any, ByVal ByteLen As Long)
Private Sub Command1_Click()
Dim s1 As String, s2 As String
s1 = "asdf"
s2 = Space(255)
CopyMemory s2, s1, Len(s1)
Debug.Print s2
End SubOption Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSrc As Any, ByVal ByteLen As Long)
Private Sub Command1_Click()
Dim s1 As String, s2 As String
s1 = "asdf"
s2 = Space(255)
CopyMemory s2, StrPtr(s1), Len(s1)
Debug.Print StrConv(s2, vbFromUnicode)
End Sub
Private Declare Function MyFunction Lib "MyDll.dll" (ByVal x As Integer, ByVal y As Integer, byval z As Integer) As Integer
Private Sub Command1_Click()
Dim x, y, z, ret As Integer
x = 10
y = 10
z = 10
ret = MyFunction(x, y, varptr(z))
MsgBox "x=" + CStr(x)
MsgBox "z=" + CStr(z)
End Sub
你用integer不能说明问题,实际上传给API,string和integer是不一样的,对于byref 传递方式,integer确实是哪个变量的指针,而string类型是相当于varptr(string变量名);对于byval传递方式,integer是值传递,而string相当于是传递strptr(string变量名)
4年没再做vb项目,看来自己确实有点技术生疏了,不过还是那句话理不辩不明,呵呵
http://hi.baidu.com/avengine/blog/item/4ee4f303e86c2fec09fa937c.html
与vb参数传替