VB VC 混合编程中,VC 问题 --> USHORT vbString2pszString(LPVOID InBuffer, LPVOID OutBuffer, USHORT BufferLen)
count 是干什么的?
// ======== ======== ======== ======== ======== ======== ======== ======== ======== ========
//
USHORT vbString2pszString(LPVOID InBuffer, LPVOID OutBuffer, USHORT BufferLen)
{
//LPVOID : A 32-bit pointer to an unspecified type.
//USHORT : Unsigned SHORT.
char *vbString;
char *pszString;
int count=0;
vbString = (char*)InBuffer;
pszString = (char*)OutBuffer;
//memset : Sets buffers to a specified character.
//void *memset( void *dest, int c, size_t count );
memset(pszString, '\0', BufferLen);
while(count<2)
{
if(*vbString != '\0')
{
count = 0;
//strcat : Append a string.
//char *strcat( char *strDestination, const char *strSource );
strcat(pszString,vbString);
}
else
{
count++;
}
vbString++;
}
return 0;
}
问题点数:20、回复次数:6Top
1 楼shaosx(shaosx)回复于 2004-08-03 09:05:06 得分 0
// ======== ======== ======== ======== ======== ======== ======== ======== ======== ========
//
#include <windows.h>
#include <ole2.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
// ======== ======== ======== ======== ======== ======== ======== ======== ======== ========
//
//Each implementation of C and C++ supports some features unique to its host machine or
// operating system. Some programs, for instance, need to exercise precise control over the
// memory areas where data is placed or to control the way certain functions receive
// parameters. The #pragma directives offer a way for each compiler to offer machine- and
// operating-system-specific features while retaining overall compatibility with the C and
// C++ languages. Pragmas are machine- or operating-system-specific by definition, and are
// usually different for every compiler.
#pragma pack(1)
// ======== ======== ======== ======== ======== ======== ======== ======== ======== ========
//
typedef struct
{
long nFlags;
long nPosition;
//LPVOID : A 32-bit pointer to an unspecified type.
LPVOID vbsPathName;
LPVOID vbsFileName;
LPVOID vbsFileType;
} vbFiles;
// ======== ======== ======== ======== ======== ======== ======== ======== ======== ========
//
USHORT vbString2pszString(LPVOID InBuffer, LPVOID OutBuffer, USHORT BufferLen)
{
//LPVOID : A 32-bit pointer to an unspecified type.
//USHORT : Unsigned SHORT.
char *vbString;
char *pszString;
int count=0;
vbString = (char*)InBuffer;
pszString = (char*)OutBuffer;
//memset : Sets buffers to a specified character.
//void *memset( void *dest, int c, size_t count );
memset(pszString, '\0', BufferLen);
while(count<2)
{
if(*vbString != '\0')
{
count = 0;
//strcat : Append a string.
//char *strcat( char *strDestination, const char *strSource );
strcat(pszString,vbString);
}
else
{
count++;
}
vbString++;
}
return 0;
}
// ======== ======== ======== ======== ======== ======== ======== ======== ======== ========
//
USHORT GetvbStringLen(LPVOID InBuffer)
{
//LPVOID : A 32-bit pointer to an unspecified type.
char *t;
int count=0;
int BufLen=0;
t = (char*)InBuffer;
while(count<2)
{
if(*t != '\0')
{
count = 0;
BufLen++;
}
else
{
count++;
}
t++;
}
return(BufLen);
}
// ======== ======== ======== ======== ======== ======== ======== ======== ======== ========
//
USHORT pszString2vbString(LPVOID *OutBuffer, LPVOID InBuffer, USHORT BufLen)
{
int count=0;
char * temp;
char * temp1;
char * pszString;
temp=(char*)malloc((BufLen*2)+1);
memset(temp,'\0',((BufLen*2)+1));
temp1=temp;
pszString = (char*)InBuffer;
for (count = 0; count < BufLen; count++)
{
memset(temp1,pszString[count],1);
temp1++;
temp1++;
}
memcpy(*OutBuffer, temp, ((BufLen*2)+1));
return(1);
}
// ======== ======== ======== ======== ======== ======== ======== ======== ======== ========
//
USHORT unPackVBStr(LPVOID InBuffer, char ** OutBuffer)
{
int i;
int rc=1;
if ((i = GetvbStringLen(InBuffer)) != 0)
{
*OutBuffer=(char*)malloc((i+2)*sizeof(char));
memset(*OutBuffer,'\0',i);
vbString2pszString(InBuffer, *OutBuffer, i);
}
else
{
OutBuffer = 0;
rc = 0;
}
return rc;
}
// ======== ======== ======== ======== ======== ======== ======== ======== ======== ========
//
USHORT PackVBStr(char * InBuffer, LPVOID *OutBuffer)
{
int len;
int rc=1;
if (!OutBuffer)
rc = 0;
else
{
if (InBuffer)
{
len = GetvbStringLen(*OutBuffer);
pszString2vbString(OutBuffer, InBuffer, len);
}
else
pszString2vbString(OutBuffer, "", 0);
}
return rc;
}
// ======== ======== ======== ======== ======== ======== ======== ======== ======== ========
//
unsigned short _declspec(dllexport) Test(LPSAFEARRAY FAR * ppsaFiles)
{
unsigned int i;
vbFiles * Files;
char * pszPath;
char * pszFile;
char * pszType;
Files=(vbFiles*)((*ppsaFiles)->pvData);
for (i=0;i<((*ppsaFiles)->rgsabound->cElements);i++,Files++)
{
unPackVBStr(Files->vbsPathName, &pszPath);
unPackVBStr(Files->vbsFileName, &pszFile);
unPackVBStr(Files->vbsFileType, &pszType);
strcpy(pszType,"TEXT");
PackVBStr(pszType, &Files->vbsFileType);
unPackVBStr(Files->vbsFileType, &pszType);
}
return 1;
}
// ======== ======== ======== ======== ======== ======== ======== ======== ======== ========
Top
2 楼zhuzhufox(狐狸的小猪)回复于 2004-08-03 09:05:47 得分 10
连续两个结束符表示字符串的结束(BSTR?)
Count用来计算'\0'的Top
3 楼shaosx(shaosx)回复于 2004-08-03 09:16:21 得分 0
还是不太明白!
若仅仅碰到一个'\0'怎么办?Top
4 楼shaosx(shaosx)回复于 2004-08-03 09:22:26 得分 0
也就是说,
我对 数据结构 不太明白。
请zhuzhufox(狐狸的小猪) 指点一下。Top
5 楼jazy()回复于 2004-08-03 09:23:25 得分 10
这个问题最好不要只知道个结论,要知道原因还是自己看看MSDN里对unicode字符的说明,
尤其是BSTR及其相关数据类型的帮助,内容很多,你根据自己的需要挑着看吧,
否则很难明白vb和vc对字符串的处理Top
6 楼shaosx(shaosx)回复于 2004-08-03 09:28:42 得分 0
jazy:
OK!Top
相关问题
- LPVOID如何转换成CString?
- 转换题,怎样由CString 到 LPVOID
- 如何求得LPVOID所指内容的SIZE(字节)?
- 急!!!如何将一个结构对象转成LPVOID
- 为什么CoCreateInstance(clsidWord,NULL,CLSCTX_INPROC_SERVER,IID_IUnknown,(LPVOID*)&lpDisp);出错???
- 一个菜鸟的问题:怎样把LPVOID转换成char *?
- 怎样用LPVOID传递字符串?(在线等待)
- 请问如何将LPVOID转换成String???(在线等)
- 请问如何将LPVOID转换成String???(在线等)
- BITMAP结构中LPVOID bmBits指针求详细解释!!!!!!!!!!!!!




