From: Devin S. <de...@no...> - 2005-07-06 19:21:47
|
Hi, I'm a little confused as to why this code isn't working. I've isolated it down to the smallest bit of code that produces the error. I think I need a second pair of eyes. --- SNIP "ConnectionServer.h" ---- #ifndef CONNECTIONSERVER_H #define CONNECTIONSERVER_H #include <initguid.h> #include <objbase.h> #ifdef __cplusplus extern "C" { #endif // Define the library ID DEFINE_GUID(LIBID_ConnectionServer, 0xebaced7f,0xd51b,0x4298,0x98, 0x91, 0xd4, 0x21, 0xf5, 0x25, 0xb6, 0x11); // Define the class IDs DEFINE_GUID(CLSID_Connection, 0x9159fead,0x803c,0x4b2d,0x9d, 0x56, 0x44, 0xf8, 0x93, 0xac, 0xa, 0x9a); DEFINE_GUID(CLSID_Connector, 0x61c43cb0,0xd2ab,0x45c3,0xa5, 0x61, 0x35, 0x6c, 0xa3, 0xad, 0x48, 0x15); DEFINE_GUID(CLSID_Processor, 0x1854e28e,0xaaac,0x4d99,0x9f, 0x9b, 0xb6, 0xc5, 0x31, 0x7d, 0x84, 0xed); DEFINE_GUID(CLSID_PaymentType, 0xb2235594,0x8ff,0x40cd,0xbf, 0x6b, 0xaa, 0x9, 0x71, 0xc3, 0x88, 0x5b); DEFINE_GUID(CLSID_Adapter, 0x444f77de,0x94d4,0x4ccd,0xa6, 0xcc, 0x6c, 0x80, 0x6f, 0x31, 0x15, 0xd8); DEFINE_GUID(CLSID_Connections, 0x945cc586,0xd599,0x44c6, 0xab, 0xd6, 0x0, 0x16, 0x61, 0x12, 0x51, 0x6f); DEFINE_GUID(CLSID_Connectors, 0xf513e38e,0x2d0c,0x4a62,0x92, 0x55, 0x48, 0x8f, 0xfb, 0xc4, 0x5, 0xd4); DEFINE_GUID(CLSID_Processors, 0x48babda9,0x72c8,0x402a,0xa0, 0xe4, 0x38, 0x64, 0xe5, 0xc, 0x6f, 0x5); DEFINE_GUID(CLSID_PaymentTypes, 0xd5ad3240,0x2429,0x4e97,0x9c, 0x11, 0x68, 0x30, 0x75, 0xf6, 0xf9, 0xa5); DEFINE_GUID(CLSID_Adapters, 0xb6bee287,0x998b,0x42f4,0x82, 0x2a, 0x2e, 0xea, 0x3d, 0x1, 0x96, 0xc8); DEFINE_GUID(CLSID_Utility, 0x40347e9c,0x43b1,0x48b4,0x9b, 0xc7, 0x95, 0xd7, 0xb3, 0x65, 0x1a, 0xf7); // Define the interface IDs DEFINE_GUID(IID__Connections, 0xbd3965c8,0xd05a,0x4c33,0xac, 0xe3, 0x84, 0x2e, 0xa1, 0x96, 0xde, 0xe3); #undef INTERFACE #define INTERFACE _Connections DECLARE_INTERFACE_(_Connections, IDispatch) { STDMETHOD (QueryInterface)(THIS_ REFIID riid, void** ppv) PURE; STDMETHOD_(ULONG, AddRef) (THIS) PURE; STDMETHOD_(ULONG, Release) (THIS) PURE; STDMETHOD (GetTypeInfoCount) (THIS_ int*) PURE; STDMETHOD (GetTypeInfo) (THIS_ int, long, void** pptinfo) PURE; STDMETHOD (GetIDsOfNames) (THIS_ REFIID riid, char** rgszNames, int cNames, long lcid, long* rgdispid) PURE; STDMETHOD (Invoke) (THIS_ long dispidMember, REFIID riid, long lcid, USHORT wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr) PURE; STDMETHOD (Add) (THIS_ BSTR strConnectionName, struct _Connection* *) PURE; STDMETHOD (Refresh)(THIS_ VARIANT_BOOL *) PURE; STDMETHOD (Save)(THIS_ VARIANT_BOOL *) PURE; STDMETHOD (get_ConfigXMLPath)(THIS_ BSTR *) PURE; STDMETHOD (get_Item)(THIS_ VARIANT vntIndexKey, struct _Connection* *) PURE; STDMETHOD (get_Count)(THIS_ LONG *) PURE; STDMETHOD (get_NewEnum)(THIS_ struct IUnknown* *) PURE; }; typedef _Connections *LP_CONNECTIONS; #ifdef __cplusplus } #endif #endif // CONNECTIONSERVER_H --- SNIP-END "ConnectionServer.h" ---- --- SNIP "comtest.cpp" ---- #include <stdio.h> #include <wchar.h> #include "ConnectionServer.h" int main(void) { _Connections *m_objConnections =3D NULL; // Initiale COM CoInitialize(NULL); if (FAILED(CoCreateInstance(CLSID_Connections, NULL, CLSCTX_INPROC_SERVER, =20 IID__Connections,(LPVOID*)&m_objConnections))) m_objConnections =3D NULL; BSTR *bPath =3D NULL; if (m_objConnections) { HRESULT hr =3D m_objConnections->get_ConfigXMLPath(bPath); if (SUCCEEDED(hr)) { fwprintf(stdout, L"%s\n", bPath); } else puts("Error getting XML Path.\n"); } if (m_objConnections !=3D NULL) { m_objConnections->Release(); m_objConnections =3D NULL; } CoUninitialize(); return 0; } --- SNIP-END "comtest.cpp" ---- If I run the compiled executable I get the output "(null)". If I run the program and VB6 is "playing" the DLL in debug mode I get "Error getting XML Path." printed. The HRESULT is an Access is Denied result (0x5). Also when it's in debug mode the program never seems to enter the "ConfigXMLPath" property even though a break point is set in there.=20 Putting the equivalent code in a VBScipt file produces the correct results. It does not print (null) for the path. The VBScript is below: --- SNIP "test.vbs" ---- Dim objConnections set objConnections =3D CreateObject("ConnectionServer.Connections") If IsObject(objConnections) Then If objConnections is Nothing Then WScript.echo "Connection Server creation Failed" Else WScript.echo "Connection Server creation successful" End If End If WScript.echo "Config XML Path: " & objConnections.ConfigXMLPath --- SNIP-END "test.vbs" ---- Any help is appreciated. Thanks in advance, -- Devin Smith=20 |