MSDN 에서 찾았습니다. 에공...역시 두드리는 자에게 문은 열리나 봅니다. ^__^
HOWTO: Implement Visual C++ COM Objects Returning Recordsets
ID: Q225131
-----------------------------------------------------------------
The information in this article applies to:
Active Server Pages
ActiveX Data Objects (ADO)
Microsoft Visual C++, 32-bit Editions, versions 5.0, 6.0
Microsoft Internet Information Server versions 4.0, 5.0
-----------------------------------------------------------------
[SUMMARY]
This article describes, by example, how to implement a Visual
C++ Component Object Model (COM) object that returns a recordset
to Active Server Pages (ASP).
Implementing this incorrectly can result in memory leaks or one
of the following errors:
The operation requested by the application is not allowed if the
object is closed.
-or-
Type Mismatch
-or-
error ASP 0115 - A trappable error occured in an external
object
[MORE INFORMATION]
Use the following steps to implement a method that returns a
recordset from a Visual C++ COM object to Active Server Pages.
1. Create an ATL DLL project called PassRs.
2. Insert an ATL object named PassRsObj.
3. Add a method with the following information:
Method Name: TestMethod
Parameters : [out, retval] LPDISPATCH* ppRecordset
4. Include the following line in the objects implementation file:
#import "msado15.dll" no_namespace rename("EOF", "adoEOF")
5. Implement the method as follows:
STDMETHODIMP CPassRsObj::TestMethod(LPDISPATCH *ppRecordset )
{
_ConnectionPtr pConn;
_RecordsetPtr pRs;
pConn.CreateInstance(__uuidof(Connection));
pRs.CreateInstance(__uuidof(Recordset));
pConn->Open("DSN=pubs;uid=sa;pwd=;", (BSTR) NULL, (BSTR) NULL, -1);
//Client side cursor is required for disconnected recordsets
pRs->CursorLocation = adUseClient;
pRs->Open( "select * from authors",
pConn.GetInterfacePtr(),
adOpenKeyset, adLockOptimistic, -1);
// Disconnect the recordset
pRs->PutRefActiveConnection(NULL);
//Clone the recordset.
//NOTE: Recordset to be cloned must support bookmarks
pRs->Clone(adLockOptimistic)->QueryInterface(IID_IDispatch, (void**) ppRecordset);
pRs->Close();
pConn->Close();
pRs = NULL;
pConn = NULL;
return S_OK;
}
6. Create an ASP page with the following code:
< %
Dim rsTest, oTestPassRs
Set oTestPassRs = Server.CreateObject("PassRs.PassRsObj")
Set rsTest = oTestPassRs.TestMethod()
Do
Response.Write ( "Value in Record = " & rsTest(1) & "< BR>" )
rsTest.MoveNext
Loop until rsTest.EOF
rsTest.Close
Set rsTest = Nothing
Set oTestPassRs = Nothing
%>
출처 : wunderbar
'소프트웨어 > C++' 카테고리의 다른 글
ASP Component (C++) 정리 잘 된 사이트 (0) | 2007.01.10 |
---|---|
서버 컴포넌트 디버깅하기 (0) | 2007.01.10 |
ATL COM 매개변수 디폴트 값 주기 (0) | 2007.01.10 |