服务器端没有什么不同的
客户的例子
// client.cpp : Defines the entry point for the console application.
//
#include "atlbase.h"
#include "..\dbsvr\dbsvr.h"
#import "H:\program files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
const IID IID_IDbAccess = {0xB5A79775,0x7878,0x4984,{0xA0,0x97,0xEC,0x57,0xDA,0xFC,0xB0,0x1E}};
const CLSID CLSID_DbAccess = {0x1C0B24CC,0x47EF,0x4B7B,{0xA0,0xB7,0xBA,0x33,0x6F,0x25,0x83,0x86}};
int main(int argc, char* argv[])
{
USES_CONVERSION;
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if(FAILED(hr))
return -1;
COAUTHIDENTITY AuthIdentity;
AuthIdentity.User=L"wyzegg";
AuthIdentity.UserLength=wcslen(L"wyzegg");
AuthIdentity.Password=L"password";
AuthIdentity.PasswordLength=wcslen(L"password");
AuthIdentity.Domain=L"";
AuthIdentity.DomainLength=wcslen(L"");
AuthIdentity.Flags=SEC_WINNT_AUTH_IDENTITY_UNICODE;
COAUTHINFO AuthInfo;
AuthInfo.dwAuthnSvc=/*RPC_C_AUTHN_GSS_KERBEROS;//*/RPC_C_AUTHN_WINNT;
AuthInfo.dwAuthzSvc=RPC_C_AUTHZ_NONE/*RPC_C_AUTHZ_NONE*/;
AuthInfo.pwszServerPrincName=NULL;
AuthInfo.dwAuthnLevel=/*RPC_C_AUTHN_LEVEL_CONNECT;//*/RPC_C_AUTHN_LEVEL_DEFAULT;
AuthInfo.dwImpersonationLevel=RPC_C_IMP_LEVEL_IMPERSONATE;
AuthInfo.pAuthIdentityData=&AuthIdentity;
AuthInfo.dwCapabilities=EOAC_NONE;
COSERVERINFO ServerInfo={0,L"139.1.8.5",&AuthInfo,0};
MULTI_QI qi[2]={{&IID_IUnknown,NULL,0},{&IID_IDbAccess,NULL,0}};
IDbAccess *pDbAccess;
hr=CoCreateInstanceEx(CLSID_DbAccess ,NULL,CLSCTX_REMOTE_SERVER,&ServerInfo,2,(MULTI_QI*)&qi);
switch(hr)
{
case S_OK:
printf("Indicates success.\n");
break;
case REGDB_E_CLASSNOTREG :
printf("A specified class is not registered in the registration database. Also can indicate that the type of server you requested in the CLSCTX enumeration is not registered or the values for the server types in the registry are corrupt.\n");
CoUninitialize();
return -1;
case CLASS_E_NOAGGREGATION :
printf("This class cannot be created as part of an aggregate.\n");
CoUninitialize();
return -1;
case CO_S_NOTALLINTERFACES :
printf("At least one, but not all of the interfaces requested in the pResults array were successfully retrieved. The hr field of each of the MULTI_QI structures in pResults indicates with S_OK or E_NOINTERFACE whether the specific interface was returned. \n");
CoUninitialize();
return -1;
case E_NOINTERFACE:
printf("None of the interfaces requested in the pResults array were successfully retrieved.\n");
CoUninitialize();
return -1;
default:
printf("cannot create object\n");
CoUninitialize();
return -1;
}
pDbAccess=(IDbAccess *)qi[1].pItf;
LPDISPATCH lpRs;
hr=pDbAccess->SetDbFilePath(SysAllocString(L"E:\\com+\\record\\user.mdb"));
if(hr!=0)
{
pDbAccess->Release();
CoUninitialize();
return 0;
}
hr=pDbAccess->Connect();
if(hr!=0)
{
pDbAccess->Release();
CoUninitialize();
return 0;
}
hr=pDbAccess->ExcuteQuery(SysAllocString(L"select * from user"),&lpRs);
if(hr!=0)
{
pDbAccess->Release();
CoUninitialize();
return 0;
}
_RecordsetPtr pUserSet(lpRs);
FieldsPtr pFieldsPtr;
FieldPtr pFieldPtr;
char name[255];
long nRow=0;
while (!pUserSet->EndOfFile)
{
nRow++;
pFieldsPtr = pUserSet->Fields;
pFieldPtr = pFieldsPtr->Item["user_name"];
if( pFieldPtr->Value.vt==VT_NULL )
strcpy(name,"");
else
strcpy(name,_bstr_t(pFieldPtr->Value));
printf("row%d's user_name is %s\n",nRow,name);
pUserSet->MoveNext();
}
pUserSet->Close();
pDbAccess->DisConnect();
pDbAccess->Release();
CoUninitialize();
return 0;
}
客户的例子
// client.cpp : Defines the entry point for the console application.
//
#include "atlbase.h"
#include "..\dbsvr\dbsvr.h"
#import "H:\program files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
const IID IID_IDbAccess = {0xB5A79775,0x7878,0x4984,{0xA0,0x97,0xEC,0x57,0xDA,0xFC,0xB0,0x1E}};
const CLSID CLSID_DbAccess = {0x1C0B24CC,0x47EF,0x4B7B,{0xA0,0xB7,0xBA,0x33,0x6F,0x25,0x83,0x86}};
int main(int argc, char* argv[])
{
USES_CONVERSION;
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if(FAILED(hr))
return -1;
COAUTHIDENTITY AuthIdentity;
AuthIdentity.User=L"wyzegg";
AuthIdentity.UserLength=wcslen(L"wyzegg");
AuthIdentity.Password=L"password";
AuthIdentity.PasswordLength=wcslen(L"password");
AuthIdentity.Domain=L"";
AuthIdentity.DomainLength=wcslen(L"");
AuthIdentity.Flags=SEC_WINNT_AUTH_IDENTITY_UNICODE;
COAUTHINFO AuthInfo;
AuthInfo.dwAuthnSvc=/*RPC_C_AUTHN_GSS_KERBEROS;//*/RPC_C_AUTHN_WINNT;
AuthInfo.dwAuthzSvc=RPC_C_AUTHZ_NONE/*RPC_C_AUTHZ_NONE*/;
AuthInfo.pwszServerPrincName=NULL;
AuthInfo.dwAuthnLevel=/*RPC_C_AUTHN_LEVEL_CONNECT;//*/RPC_C_AUTHN_LEVEL_DEFAULT;
AuthInfo.dwImpersonationLevel=RPC_C_IMP_LEVEL_IMPERSONATE;
AuthInfo.pAuthIdentityData=&AuthIdentity;
AuthInfo.dwCapabilities=EOAC_NONE;
COSERVERINFO ServerInfo={0,L"139.1.8.5",&AuthInfo,0};
MULTI_QI qi[2]={{&IID_IUnknown,NULL,0},{&IID_IDbAccess,NULL,0}};
IDbAccess *pDbAccess;
hr=CoCreateInstanceEx(CLSID_DbAccess ,NULL,CLSCTX_REMOTE_SERVER,&ServerInfo,2,(MULTI_QI*)&qi);
switch(hr)
{
case S_OK:
printf("Indicates success.\n");
break;
case REGDB_E_CLASSNOTREG :
printf("A specified class is not registered in the registration database. Also can indicate that the type of server you requested in the CLSCTX enumeration is not registered or the values for the server types in the registry are corrupt.\n");
CoUninitialize();
return -1;
case CLASS_E_NOAGGREGATION :
printf("This class cannot be created as part of an aggregate.\n");
CoUninitialize();
return -1;
case CO_S_NOTALLINTERFACES :
printf("At least one, but not all of the interfaces requested in the pResults array were successfully retrieved. The hr field of each of the MULTI_QI structures in pResults indicates with S_OK or E_NOINTERFACE whether the specific interface was returned. \n");
CoUninitialize();
return -1;
case E_NOINTERFACE:
printf("None of the interfaces requested in the pResults array were successfully retrieved.\n");
CoUninitialize();
return -1;
default:
printf("cannot create object\n");
CoUninitialize();
return -1;
}
pDbAccess=(IDbAccess *)qi[1].pItf;
LPDISPATCH lpRs;
hr=pDbAccess->SetDbFilePath(SysAllocString(L"E:\\com+\\record\\user.mdb"));
if(hr!=0)
{
pDbAccess->Release();
CoUninitialize();
return 0;
}
hr=pDbAccess->Connect();
if(hr!=0)
{
pDbAccess->Release();
CoUninitialize();
return 0;
}
hr=pDbAccess->ExcuteQuery(SysAllocString(L"select * from user"),&lpRs);
if(hr!=0)
{
pDbAccess->Release();
CoUninitialize();
return 0;
}
_RecordsetPtr pUserSet(lpRs);
FieldsPtr pFieldsPtr;
FieldPtr pFieldPtr;
char name[255];
long nRow=0;
while (!pUserSet->EndOfFile)
{
nRow++;
pFieldsPtr = pUserSet->Fields;
pFieldPtr = pFieldsPtr->Item["user_name"];
if( pFieldPtr->Value.vt==VT_NULL )
strcpy(name,"");
else
strcpy(name,_bstr_t(pFieldPtr->Value));
printf("row%d's user_name is %s\n",nRow,name);
pUserSet->MoveNext();
}
pUserSet->Close();
pDbAccess->DisConnect();
pDbAccess->Release();
CoUninitialize();
return 0;
}
解决方案 »
- 初学图形学,有什么书籍推荐啊
- [HELP]求语音转换成文本的类库?
- 静默安装会生成setup.log,如何禁止其产生?
- 存储当前View的BMP文件为什么要有这段代码啊??
- 如果打开window资源管理窗口
- 请教!怎样确认光盘里是否有某个文件,我写的代码怎么也过不去,不知道哪里有问题了?
- (高分求助)想做一个路由器模拟器,不知如何搭框架
- "user breakpoint called from code at 0x77fa018c"是错误吗?
- 编辑框输入的问题!
- 用VC获取操作系统已经安装的补丁
- 感谢所有说过“元旦快乐”的人,祝所有人今夜不编程,let's go game game game
- 怎样虚拟一个FILE文件?
成功之后,一定给分。
如何生成代理DLL和存根DLL,如何分发
在本栏已经多次问到,你可以搜索一下
DAOBADAN @163,NET