_bstr_t strcon="Provider=SQLOLEDB;Server=FILESERVER;Database=pubs;uid=sa;pwd=";
STDMETHODIMP CAcon::conptr(BSTR str, _Recordset **ptr)
{
try
{
CoInitialize(NULL);
_ConnectionPtr conptr(__uuidof(Connection));
_RecordsetPtr recptr(__uuidof(Recordset));
conptr->CursorLocation=adUseClient;
conptr->Open(strcon,"","",-1);
recptr->CursorLocation=adUseClient;
recptr->Open(_variant_t(str),_variant_t((IDispatch*)conptr,true),adOpenDynamic,adLockBatchOptimistic,adCmdText);
recptr->QueryInterface(__uuidof(_Recordset),(void**) ptr);
CoUninitialize();
} catch (_com_error &e)
{
MessageBox(NULL,e.Description(),"ss",MB_OK|MB_ICONWARNING);
}下面是编译的问题,编译前我在post-bulid step 中写了nmake -F strconps.mkd:\工作文档\vc\strcon\debug\msado15.tlh(405) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
Compiling...
strcon.cpp
Acon.cpp
D:\工作文档\vc\strcon\Acon.cpp(13) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify -GX
Generating Code...
Linking...
Performing registration
Server registration done!
Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
NMAKE : fatal error U1073: don't know how to make 'dlldata.obj'
Stop.
Error executing c:\winnt\system32\cmd.exe.strcon.exe - 1 error(s), 2 warning(s)
STDMETHODIMP CAcon::conptr(BSTR str, _Recordset **ptr)
{
try
{
CoInitialize(NULL);
_ConnectionPtr conptr(__uuidof(Connection));
_RecordsetPtr recptr(__uuidof(Recordset));
conptr->CursorLocation=adUseClient;
conptr->Open(strcon,"","",-1);
recptr->CursorLocation=adUseClient;
recptr->Open(_variant_t(str),_variant_t((IDispatch*)conptr,true),adOpenDynamic,adLockBatchOptimistic,adCmdText);
recptr->QueryInterface(__uuidof(_Recordset),(void**) ptr);
CoUninitialize();
} catch (_com_error &e)
{
MessageBox(NULL,e.Description(),"ss",MB_OK|MB_ICONWARNING);
}下面是编译的问题,编译前我在post-bulid step 中写了nmake -F strconps.mkd:\工作文档\vc\strcon\debug\msado15.tlh(405) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
Compiling...
strcon.cpp
Acon.cpp
D:\工作文档\vc\strcon\Acon.cpp(13) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify -GX
Generating Code...
Linking...
Performing registration
Server registration done!
Microsoft (R) Program Maintenance Utility Version 6.00.8168.0
Copyright (C) Microsoft Corp 1988-1998. All rights reserved.
NMAKE : fatal error U1073: don't know how to make 'dlldata.obj'
Stop.
Error executing c:\winnt\system32\cmd.exe.strcon.exe - 1 error(s), 2 warning(s)
Error executing c:\winnt\system32\cmd.exe.你查看一下 setting - > post build setup
// strcon.idl : IDL source for strcon.dll
//// This file will be processed by the MIDL tool to
// produce the type library (strcon.tlb) and marshalling code.import "oaidl.idl";
import "ocidl.idl";
[
uuid(D2AED239-6993-4163-B362-1CDF43B8E85C),
version(1.0),
helpstring("strcon 1.0 Type Library")
]
library STRCONLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
importlib("c:\Program Files\Common Files\System\ado\msado15.dll");//为了让下面的 _Recordset **ptr必须添加的,下面到***那些语句是从上面import "ocidl.idl";语句下面移到下面的
[
object,
uuid(297EA435-3D99-40F1-B513-9827912234AA),
dual,
helpstring("IAcon Interface"),
pointer_default(unique)
]
interface IAcon : IDispatch
{
[id(1), helpstring("method conptr")] HRESULT conptr([in] BSTR str,[out,retval] _Recordset **ptr);
};
//***到这里
[
uuid(F78BF9C4-4098-4E22-8909-C5204CF7934C),
helpstring("Acon Class")
]
coclass Acon
{
[default] interface IAcon;
};
};