Import Type Library Note Successful Order

xiaoxiao2021-03-06  61

COM components Universal ADO Access Database, using components in VC, the type library of importing components is an error ------------------------------- ----------------------------------- Maybe this problem is really not a problem for others, but if When I met, I will be died, so I still wrote it, I hope that others will meet.

It is time to get help: i. Problem Overview: I used ADO (Msado15.dll) when I was doing a component, access the database (SQL2000). <1> component side: method definition: HRESULT GETRECORDSET ([in] BSTR queryCmd, [out, retval] _Recordset ** RecordsetPtr); implemented: STDMETHODIMP CQueryRec :: GetRecordset (BSTR queryCmd, _Recordset ** RecordsetPtr) {AFX_MANAGE_STATE (AfxGetStaticModuleState ())

Coinitialize (NULL);

_ConnectionPtr PCON (__ uuidof (connection)); _Commandptr PCMD (__ uuidof (command)); _recordsetptr pset (__ uuidof (recordset));

PCON-> Open ("provider = sqloledb.1; data source = 127.0.0.1; initial catalog = northwind"), _t ("sa"), _ t (""), adopenunSpecified; PCMD-> ActiveConnection = PCON ; CString command (queryCmd); pCmd-> CommandText = command.operator LPCTSTR (); pSet-> PutRefSource (pCmd); pSet-> CursorLocation = adUseClient; _variant_t vNull (DISP_E_PARAMNOTFOUND, VT_ERROR); pSet-> Open (vNull, vNull , AdoPENDYNAMIC, ADLOCKTIMISTIC, ADCMDTEXT); Pset-> Queryinterface (__ uuidof (_recordset), (void **) RecordSetPtr);

Couninitialize (); return s_ok;} <2> VC client: 1. In the VC client uses components to import the type library of components, I also imported the type library in the Type Library #import "GetRec.TLB" Using Namespace getReclib; 2. Then I also thought that there is a smart pointer to the _RecordSetPtr type in the type returned, I have introduced Msado15.dll #import "msado15.dll" NO_NAMESPACE RENAME ("EOF", "endoffile")

II. Error message: After doing the above, I joined the method of using the component, all the best, started, began to compile, the error is as follows: ...: error C2146: Syntax error: lack ";" (in the identifier "getRecordset" Front) ...: Error C2501: "GetReclib :: iQueryRec :: _ RecordSetptr": Missing store or type specifier ...: warning c4183: "getRecordset": Miss return type; assume that a member returns "int" Function ...: error C2143: Syntax error: Miss ";" ("in front of" getReclib :: iQueryRec :: getRecordset) ...: error C2433: "_recordSetPtr": Do not allow "inline" in the data declaration ...: error C2501: "_recordSetPtr": Missing store or type specifier ...: Error C2064: I don't calculate the function of accepting 2 parameters. I have checked a lot of times, there is no other problem, how questions This is the case, depressed, mainly the mistakes of this problem, the prompt is lacking ";" What is the syntax error, but there is no syntax error, I am still sure, because I am only a new Write #import "getrec.tlb" is wrong, let me confuse this component is no problem with VB call this component, normal, I really don't know how it, because this problem doesn't want other, I You can also check the mistakes with usa, this is really no problem, I also start thinking is a bug.iv of VC. Question Solution: After three or four days, I have n'thing to take this code to ponder, Finally, inadvertently discovered that he made a mistake, "the order of import library" I am in stdafx.h in the VC client: 1. # Import "getRec.tlb" 2. # import "msado15.dll" no_namespace Rename ("EOF", "Endoffile") VC compiler "getRec.tlh", that is, the header file of the component, there is _recordsetptr, but in this VC client can not recognize this type, I really, I In the second step, "msado15.dll" is imported. However, before this, the header file cannot be identified, the compiler is topped on the top of a file, so I don't know _Recordset PTR, so I changed the introduction, OK, No Problem!

转载请注明原文地址:https://www.9cbs.com/read-84529.html

New Post(0)