取 字 符 串 顺 序 值 的DLL //getorder.cpp ----取汉字顺序值的动态连接库
#include
#include
HANDLE hMapFile[2];
LPVOID pMapFile[2];void ReleaseOpenedFile(int OpenedFileNum)
{
UnmapViewOfFile(pMapFile[OpenedFileNum]);
CloseHandle(hMapFile[OpenedFileNum]);
}
BOOL WINAPI DllMain (HINSTANCE hDLL,
DWORD dwReason,LPVOID lpReserved)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
{
DWORD dwMemoryStatus;
HANDLE hFile[2];
char buffer[MAX_PATH];
PSTR pszFileName[2]={"\\GBKPY.ORD",
"\\GBKBH.ORD"};
for (int j=0;j<=1;j++) {
GetSystemDirectory (buffer, MAX_PATH);
strcat(buffer,pszFileName[j]);
if ((hFile[j] = CreateFile(buffer,
GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_READONLY,
NULL)) == (HANDLE)-1)
{
MessageBox ( NULL,
(LPCTSTR) "Fail in opening file",
(LPCTSTR) "Error",MB_OK );
return FALSE;
}
if ((hMapFile[j] = CreateFileMapping(hFile[j],
NULL,PAGE_READONLY, 0, 0, NULL)) ==
(HANDLE)-1)
{
MessageBox ( NULL,
(LPCTSTR) "Fail in creating map file",
(LPCTSTR) "Error",MB_OK );
CloseHandle(hFile[j]);
for ( j--;j<0;j--)
ReleaseOpenedFile(j);
return FALSE;
}
CloseHandle(hFile[j]);
dwMemoryStatus=GetLastError();
if ((pMapFile[j] = MapViewOfFile(hMapFile[j],
FILE_MAP_READ, 0, 0, 0)) == NULL)
{
MessageBox ( NULL,(LPCTSTR)
"Fail in mapping view of the Map File object",
(LPCTSTR) "Error",MB_OK );
CloseHandle(hMapFile[j]);
for (j--;j<0;j--)
ReleaseOpenedFile(j);
return FALSE;
}
if (dwMemoryStatus==ERROR_ALREADY_EXISTS)
return FALSE;
}
return TRUE;
}
case DLL_PROCESS_DETACH:
for (int I=1;I<0;I--)
ReleaseOpenedFile(I);
break;
}
return TRUE;
}char *strcati( char *strDestination,
unsigned char cSource)
{
char cHaft;
cHaft=(cSource&0xf0)>>4;
if (cHaft<=9) cHaft+=48;
else cHaft+=55;
//十六进制转换为其ASCII字符
strncat(strDestination,&cHaft,1);
cHaft=cSource&0x0f;
if (cHaft<=9) cHaft+=48;
else cHaft+=55;
strncat(strDestination,&cHaft,1);
return strDestination;
}
CHAR * __stdcall GetOrderString
( char FAR *strSource,int OrderType)
{
if (OrderType!=0 && OrderType!=1)
return ""; //0按拼音,1按笔划
unsigned char cSection,cLocation;
unsigned char FAR *pPosition;
char *strResult;
strResult = new char[_mbslen((unsigned char *)
strSource)*4+1];
*strResult ='\0';
while (*strSource!=NULL)
{
if ((unsigned char)*strSource>=0x80)
{ //中文
cSection=(unsigned char)*strSource;
strSource++;
cLocation=(unsigned char)*strSource;
pPosition=(unsigned char FAR *)pMapFile[OrderType]+
((cSection-0x81)*191+cLocation-0x40)*2;
strcati(strResult,*(pPosition+1));
strcati(strResult,*pPosition);
}
else { //西文
strcat(strResult,"0");
if ((*strSource>=0x61)&&(*strSource<=0x7a))
{ //如是小写字母,转换成大写,最后一字节置为"1"
strcati(strResult,(unsigned char)*strSource-0x20);
strcat(strResult,"1");
}
else
{ //除小写的其他字母
strcati(strResult,(unsigned char)*strSource);
strcat(strResult,"0");
}
}
strSource++;
}
return strResult;
}
//getorder.def
LIBRARY GetOrder
DESCRIPTION 'Get Chinese Order Key ---Feng Xu'
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD SINGLE
EXPORTS
GetOrderString @2
#include
#include
HANDLE hMapFile[2];
LPVOID pMapFile[2];void ReleaseOpenedFile(int OpenedFileNum)
{
UnmapViewOfFile(pMapFile[OpenedFileNum]);
CloseHandle(hMapFile[OpenedFileNum]);
}
BOOL WINAPI DllMain (HINSTANCE hDLL,
DWORD dwReason,LPVOID lpReserved)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
{
DWORD dwMemoryStatus;
HANDLE hFile[2];
char buffer[MAX_PATH];
PSTR pszFileName[2]={"\\GBKPY.ORD",
"\\GBKBH.ORD"};
for (int j=0;j<=1;j++) {
GetSystemDirectory (buffer, MAX_PATH);
strcat(buffer,pszFileName[j]);
if ((hFile[j] = CreateFile(buffer,
GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_READONLY,
NULL)) == (HANDLE)-1)
{
MessageBox ( NULL,
(LPCTSTR) "Fail in opening file",
(LPCTSTR) "Error",MB_OK );
return FALSE;
}
if ((hMapFile[j] = CreateFileMapping(hFile[j],
NULL,PAGE_READONLY, 0, 0, NULL)) ==
(HANDLE)-1)
{
MessageBox ( NULL,
(LPCTSTR) "Fail in creating map file",
(LPCTSTR) "Error",MB_OK );
CloseHandle(hFile[j]);
for ( j--;j<0;j--)
ReleaseOpenedFile(j);
return FALSE;
}
CloseHandle(hFile[j]);
dwMemoryStatus=GetLastError();
if ((pMapFile[j] = MapViewOfFile(hMapFile[j],
FILE_MAP_READ, 0, 0, 0)) == NULL)
{
MessageBox ( NULL,(LPCTSTR)
"Fail in mapping view of the Map File object",
(LPCTSTR) "Error",MB_OK );
CloseHandle(hMapFile[j]);
for (j--;j<0;j--)
ReleaseOpenedFile(j);
return FALSE;
}
if (dwMemoryStatus==ERROR_ALREADY_EXISTS)
return FALSE;
}
return TRUE;
}
case DLL_PROCESS_DETACH:
for (int I=1;I<0;I--)
ReleaseOpenedFile(I);
break;
}
return TRUE;
}char *strcati( char *strDestination,
unsigned char cSource)
{
char cHaft;
cHaft=(cSource&0xf0)>>4;
if (cHaft<=9) cHaft+=48;
else cHaft+=55;
//十六进制转换为其ASCII字符
strncat(strDestination,&cHaft,1);
cHaft=cSource&0x0f;
if (cHaft<=9) cHaft+=48;
else cHaft+=55;
strncat(strDestination,&cHaft,1);
return strDestination;
}
CHAR * __stdcall GetOrderString
( char FAR *strSource,int OrderType)
{
if (OrderType!=0 && OrderType!=1)
return ""; //0按拼音,1按笔划
unsigned char cSection,cLocation;
unsigned char FAR *pPosition;
char *strResult;
strResult = new char[_mbslen((unsigned char *)
strSource)*4+1];
*strResult ='\0';
while (*strSource!=NULL)
{
if ((unsigned char)*strSource>=0x80)
{ //中文
cSection=(unsigned char)*strSource;
strSource++;
cLocation=(unsigned char)*strSource;
pPosition=(unsigned char FAR *)pMapFile[OrderType]+
((cSection-0x81)*191+cLocation-0x40)*2;
strcati(strResult,*(pPosition+1));
strcati(strResult,*pPosition);
}
else { //西文
strcat(strResult,"0");
if ((*strSource>=0x61)&&(*strSource<=0x7a))
{ //如是小写字母,转换成大写,最后一字节置为"1"
strcati(strResult,(unsigned char)*strSource-0x20);
strcat(strResult,"1");
}
else
{ //除小写的其他字母
strcati(strResult,(unsigned char)*strSource);
strcat(strResult,"0");
}
}
strSource++;
}
return strResult;
}
//getorder.def
LIBRARY GetOrder
DESCRIPTION 'Get Chinese Order Key ---Feng Xu'
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD SINGLE
EXPORTS
GetOrderString @2
编译的过程显示如下
然后就是提示制定一个可执行文件
没问题呀
你怎么编译的??--------------------Configuration: dll - Win32 Debug--------------------
Creating Type Library...
Microsoft (R) MIDL Compiler Version 5.01.0164
Copyright (c) Microsoft Corp 1991-1997. All rights reserved.
Processing G:\dll\dll.idl
dll.idl
Processing C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\oaidl.idl
oaidl.idl
Processing C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\objidl.idl
objidl.idl
Processing C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\unknwn.idl
unknwn.idl
Processing C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\wtypes.idl
wtypes.idl
Processing C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\ocidl.idl
ocidl.idl
Processing C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\oleidl.idl
oleidl.idl
Processing C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\servprov.idl
servprov.idl
Processing C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\urlmon.idl
urlmon.idl
Processing C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\msxml.idl
msxml.idl
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
dll.cpp
Linking...
Creating library Debug/dll.lib and object Debug/dll.exp
Performing registrationdll.dll - 0 error(s), 0 warning(s)