com

Initialize Critical Section only once for a process

拟墨画扇 提交于 2019-12-12 10:39:42
问题 In a multi threaded application, is there a way to ensure that a Critical Section is initialized only once except for putting the code in DLL main() ?? 回答1: I'd suggest wrapping the CRITICAL_SECTION with a class that will handle the initialization and uninitialization of the critical section object in its constructor and destructor. This way, you'll be thread safe in most cases. (You'll have to make sure no one accesses the object before its constructor completes, but that's relatively easy.)

Sending and receiving arrays over COM

≯℡__Kan透↙ 提交于 2019-12-12 09:52:37
问题 What is the right way to receive and send arrays over COM? Here's my attempt so far: a safearray of doubles wrapped in a variant. //takes variant holding safearray of doubles //returns a similar variant having multipled every element by 2 STDMETHODIMP MyComClass::safearraytimestwo(VARIANT in, VARIANT* out) { CComSafeArray<double> sa_in; sa_in.Attach(*in.pparray); ULONG size = sa_in.GetCount(); CComSafeArray<double> *out_sa = new CComSafeArray<double>(size); for (long i=0;i<size;i++) out_sa-

return Array from C# to Classic ASP with COM

心不动则不痛 提交于 2019-12-12 09:43:37
问题 I am trying to return an array from c# to classic asp using com. This post helped me lot, but I still have problems: I have the following method in c#: public object[] returnStuff () { return new object[] {'1','2','3'}; } My classic ASP: dim responseArray1 responseArray1 = RegusSoapComponent.returnStuff() response.write("Type of Array one is " & VarType(responseArray1)) response.write("Type of Array one is " & responseArray1(1)) My output is: response is Type of Array one is 8204 Microsoft

what's wrong in my code related to COM?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 09:14:57
问题 *****BLOCK_1**** if( strcmpi(appName.c_str(),MSSQL)==0 ||strcmpi(appName.c_str(),MSSQL2005)==0 ) { if (FAILED(CoCreateInstance (CLSID_SQLDMOServer, NULL, CLSCTX_INPROC_SERVER, IID_ISQLDMOServer, (LPVOID*)&m_pSQLServer))) { DMOAvailable=false; IDiscoverPtr pICalc; HRESULT hRes=CoCreateInstance(Test::CLSID_SqlClass, NULL, CLSCTX_INPROC_SERVER,Test::IID_IDiscover, reinterpret_cast<void**> (&pICalc)); if(FAILED(hRes)) { cout << "CoCreateInstance Failed on CLSID_SQLDMOServer\n"; return FALSE; } **

How to write simple background thread in CWorkerThread

微笑、不失礼 提交于 2019-12-12 09:02:00
问题 I'm trying to asynchronously run function in my add-on for Internet Explorer (I'm writing BHO in VC++). As suggested here I'm trying to use CWorkerThread. I've been trying to figure it out for hours but still have no idea how to do it. I don't have much experience in ATL. The lack of a good documentations or tutorials on Internet is killing me. I'm creating class by Add->Class and choosing ATL Simple Object (that's how you add classed to ATL project right?). But how to implement this

Best method of calling managed code(c#) from unmanaged C++

混江龙づ霸主 提交于 2019-12-12 08:55:00
问题 We have developed a s/w architecture consisting of set of objects developed in C#. They make extensive use of events to notify the client of changes in status, etc. The intention originally was to allow legacy code to use these managed objects through COM interop services. That was easy to write in the design specification but, I'm seeing that actually implementing it is more problematic. I've searched for many hours looking for a good sample of event handling using this method. Before we

32 and 64 bit interoperability on 64-bit Windows

六眼飞鱼酱① 提交于 2019-12-12 08:43:54
问题 Is there a good thorough authoritative reference that discusses interoperability between 32-bit and 64-bit processes? Based on googling I have deduced that: A 32-bit DLL can only reside in a 32-bit process, and a 64-bit DLL only in a 64-bit process. 32 and 64-bit processes can only communicate using loosely coupled message systems, such as network communications, which means they can communicate using COM/DCOM. 32 and 64-bit COM components have different registry entries. A component is

how does the .RGS file works

孤者浪人 提交于 2019-12-12 08:38:18
问题 In the .rgs file, there are some registry info, and I want to know how does the info in .rgs file added into regetry? I have a project AAA and it will generate the file AAA.DLL , and there is a file xxx.rgs which contains the registry info, and the AAA.DLL is built, then it will be deployed to another machine B, so I don't know how the registy info can be added on machine B, do I need register AAA.dll using regsvr32 command? 回答1: Usually your code calls CComModule::UpdateRegistryFromResource(

Which is correct? catch (_com_error e) or catch (_com_error& e)?

情到浓时终转凉″ 提交于 2019-12-12 08:24:43
问题 Which one should I use? catch (_com_error e) or catch (_com_error& e) 回答1: The second. Here is my attempt at quoting Sutter "Throw by value, catch by reference" Learn to catch properly: Throw exceptions by value (not pointer) and catch them by reference (usually to const ). This is the combination that meshes best with exception semantics. When rethrowing the same exception, prefer just throw; to throw e; . Here's the full Item 73. Throw by value, catch by reference. The reason to avoid

How to pass a SAFEARRAY from C# to COM?

筅森魡賤 提交于 2019-12-12 08:14:22
问题 I have an ATL COM Server, where the method for the interface is CVivsBasic::UpdateSwitchPlan(BSTR plan_name, SAFEARRAY* plan) And the IDL for this function looks like typedef struct { LONG time_to_play; BSTR ecportid; } SwitchPlanItem; HRESULT UpdateSwitchPlan([in] BSTR plan_name, [in] SAFEARRAY(SwitchPlanItem) plan) ; I tried to call it from C# like this: internal void UpdateSwitch(string plan_name, string ecportid) { SwitchPlanItem sp1; sp1.time_to_play = 33; sp1.ecportid = ecportid;