|
I am having some difficulty in my C++ app with memory management. Currently the client app sets up a struct **pPointer that is passed to the COM+ method on the server. The server then reads a database and creates a record set. This record set is processed and the server then CoTaskMemAlloc’s space for each of the processed records. The array of pointers is then passed back to the client.
The pointers all seem to be marshaled fine. The data is processed, and then I CoTaskMemFree the pointers, and release the Access Object to decrement the object reference count. Even though the object seems to have no more references to it (ie the object is no longer spinning in Component Services), the server (dllhost.exe) is still holding on to the memory that was allocated on the server. After about 30 minutes the memory is eventually free’d. However the memory use is very large and multiple clients are utilizing the system. It does not take long to run out of resources and the server crashes with a ‘COM Surrogate error’ . My guess is that when the server runs out of memory, it errors and returns a NULL pointer. As Windows is trying to marshal the null pointer, the error situation occurs (but this is just a guess, it could be a bad uninitialized pointer).
I need to figure out how to free the memory on the COM server after I am done with it, so that it can be released. Any help would be greatly appreciated.
Client Side Code Snippit:
<br />
hr = CoCreateInstance( CLSID_ValuesAccessObject,<br />
0,<br />
CLSCTX_ALL,<br />
IID_IValuesAccessObject,<br />
(void**)&m_pidsrtval );<br />
<br />
...<other processing>...<br />
<br />
hr = m_pidsrtval->GetAllValues( GetDbConnectionString(),<br />
&nValues,<br />
&pspdcrtbv );<br />
<br />
<br />
...<other processing>...<br />
<br />
for( int i=0; i<nValues; i++ )<br />
{<br />
SPDCRTBV *paspdcrtbv = &((*ppsptbvValues)[i]);<br />
<br />
CoTaskMemFree(paspdcrtbv->pdvQualifiers);<br />
paspdcrtbv->pdvQualifiers = NULL;<br />
<br />
CoTaskMemFree(paspdcrtbv->pdvFacts);<br />
paspdcrtbv->pdvFacts = NULL;<br />
<br />
}<br />
<br />
CoTaskMemFree(pspdcrtbv);<br />
m_pidsrtval->Release(); <br />
Chris
|
|
|
|
|
hi everyone,
i created a activex control(.ocx),and placed the same in the form for testing,after placing not able to move(drag) the control to other places in the form
pls let me know whats missing on my control,
thanks n advance
rahul
rahul
|
|
|
|
|
Hi,
I have to build a layer of serviced components over a DAL (data access layer). Now this DAL was written using interop in VC++.
I built my component using a snk - which worked fine till i added the code to access DAL. Now it gives me an error sayin that assemly cannot be created as DAL does not have a strong name.
How do I get rid of this problem? How can i reuse the existing component without having to rewrite it in .net environment?
I recently read an article sayin that i would have to generate a strong key for the interop dll using tlbimp... but i somehow am not able to figure the parameters out ... has anybody done this?
Any help will be appreciated!
|
|
|
|
|
You only have to generate a strong name for interop if you plan to put the class library assembly into the GAC. This is recommended if you're going to share the component between applications, for example have multiple applications install the same component, but isn't actually required. The regasm utility can be made to register a class library DLL in any location using the /codebase switch; the Visual Studio deployment project's Register property, if set to 'vsdraCOM', will set the Codebase registry value appropriately if you're not installing the assembly to the GAC.
If you do install the same assembly from two different locations, then uninstall one of them, the registration will be broken for the other one. That's why the GAC is recommended.
If you do want to use the GAC, all assemblies that this one depends on will need to be signed and installed to the GAC as well. You can sign the DAL using the C++ linker's /KEYFILE option; you must specify this option in the 'Additional Options' field in the Linker options.
|
|
|
|
|
Hi,
How to register XPCOM component using XPInstall?
Thank you.
Ayesha
|
|
|
|
|
|
which book is good for COM
|
|
|
|
|
|
Essential COM (Don Box) - it goes into a lot of depth and can be quite daunting in places but it's a goldmine of important information.
|
|
|
|
|
|
Hi!
I am a newer.,
What is COM?
Why we relates this one to .net..?
If i want to know basics abt the COM Can you refer any good site..?
T.Prabu
|
|
|
|
|
search in msdn site good one
|
|
|
|
|
|
Hello friends,
For the first time I am working with ActiveX control.I have search
through net but not getting the clear idea how t handle events in
active x.
I have dialog based application and i have added a contol in that
through project ->add to project
components and control. and then add arielapi control by which i got a
wrapper class ,.cpp file, and .h. file.
THIS ARE CLASS METHOD in arielapi.cpp
<br />
CString CArielAPI::Login(LPCTSTR UserName, LPCTSTR Password, LPCTSTR<br />
UserId)<br />
{<br />
CString result;<br />
static BYTE parms[] =<br />
VTS_BSTR VTS_BSTR VTS_BSTR;<br />
InvokeHelper(0x2, DISPATCH_METHOD, VT_BSTR, (void*)&result, parms,<br />
UserName, Password, UserId);<br />
}<br />
<br />
CString CArielAPI::RequestPrices(LPCTSTR SessionId, short PageNumber)<br />
{<br />
CString result;<br />
static BYTE parms[] =<br />
VTS_BSTR VTS_I2;<br />
InvokeHelper(0x3, DISPATCH_METHOD, VT_BSTR, (void*)&result, parms,<br />
SessionId, PageNumber);<br />
return result;<br />
}<br />
<br />
<br />
CString CArielAPI::RequestDeal(LPCTSTR SessionId, long MarketNo,<br />
LPCTSTR Amount, short TradeType, LPCTSTR Exchange, short BuySell,<br />
LPCTSTR Account, LPCTSTR ClientRef)<br />
{<br />
CString result;<br />
static BYTE parms[] =<br />
VTS_BSTR VTS_I4 VTS_BSTR VTS_I2 VTS_BSTR VTS_I2 VTS_BSTR VTS_BSTR;<br />
InvokeHelper(0x4, DISPATCH_METHOD, VT_BSTR, (void*)&result, parms,<br />
SessionId, MarketNo, Amount, TradeType, Exchange, BuySell, Account,<br />
ClientRef);<br />
return result;<br />
}<br />
<br />
CString CArielAPI::RequestQuote(LPCTSTR SessionId, long MarketNo,<br />
LPCTSTR Amount, short TradeType, LPCTSTR Exchange, LPCTSTR Account,<br />
LPCTSTR ClientRef)<br />
{<br />
CString result;<br />
static BYTE parms[] =<br />
VTS_BSTR VTS_I4 VTS_BSTR VTS_I2 VTS_BSTR VTS_BSTR VTS_BSTR;<br />
InvokeHelper(0x5, DISPATCH_METHOD, VT_BSTR, (void*)&result, parms,<br />
SessionId, MarketNo, Amount, TradeType, Exchange, Account,<br />
ClientRef);<br />
return result;<br />
}<br />
<br />
AND this are events method which are getting by right clicking the
control in dialog box.
<br />
void CWartz_newDlg::OnLoginArielapictrl1(LPCTSTR SessionId, short<br />
Accepted, LPCTSTR FailureMessage)<br />
{<br />
<br />
<br />
}<br />
<br />
void CWartz_newDlg::OnPriceQuoteArielapictrl1(LPCTSTR SessionId,<br />
LPCTSTR RequestId, LPCTSTR Price, short Timeout)<br />
{<br />
<br />
}<br />
<br />
i want that when i click button it get connected to server and if
successful and get sessionid start getting the price qoute.and display
it and i dont know what to do with events if i want to fire events what
should i do for that Can anybody help me to solve this problem..
for connection button the code is :
<br />
<br />
void CWartz_newDlg::OnConnect()<br />
{<br />
CString sessionid= m_arielapi.Login("wwtest2","RD9234","wwtest2");<br />
CString serveradd=m_arielapi.GetServerAddress(sessionid);<br />
<br />
<br />
CString cstrDisplayData;<br />
cstrDisplayData.Format(_T("==>Connected to<br />
server[%s][%s]"),serveradd,sessionid);<br />
LOG(0,cstrDisplayData);<br />
}<br />
<br />
-- modified at 2:05 Wednesday 23rd August, 2006
|
|
|
|
|
We can call activex function with object of activex control. The OnConnect function will be called like this
obj.Connect
or
You can write connect code in button click event
Thanks & Regards
Kumar
abc
|
|
|
|
|
I have a atl control, having two properties. I want to use the html tag "param" to set new value. How? Thanks.
|
|
|
|
|
Hi,
I have a problem with a C++ COM server which is a service.
I define my own data structure with a bstrName and an integer for example.
And I try to get a list of the structure with a VB Client.
Here is the code of my COM object :
<br />
class ATL_NO_VTABLE CGWCServerLorCom : <br />
public CComObjectRootEx<CComSingleThreadModel>,<br />
public CComCoClass<CGWCServerLorCom, &CLSID_GWCServerLorCom>,<br />
public IGWCServerLorCom<br />
{<br />
public:<br />
CGWCServerLorCom();<br />
~CGWCServerLorCom();<br />
<br />
DECLARE_REGISTRY_RESOURCEID(IDR_GWCSERVERLORCOM)<br />
<br />
DECLARE_PROTECT_FINAL_CONSTRUCT()<br />
<br />
BEGIN_COM_MAP(CGWCServerLorCom)<br />
COM_INTERFACE_ENTRY(IGWCServerLorCom)<br />
END_COM_MAP()<br />
<br />
DECLARE_CLASSFACTORY_SINGLETON(CGWCServerLorCom)<br />
<br />
public:<br />
STDMETHOD(GetTagSpy)(long lgTagSpy, long *plgTagSpyReal, GWC_TAG_SPY_INFOS *pTagSpyInfos);<br />
lgTagSpy = size of the list given
plgTagSpyReal = real size of the list
pTagSpyInfos = list of structures
The structure is defined like this :
<br />
typedef struct ST_GWC_TAG_SPY_INFOS<br />
{<br />
BSTR bstrTagName;<br />
BSTR bstrTagValue;<br />
LONG lgTagValue;<br />
} GWC_TAG_SPY_INFOS;<br />
Actually I have 2 problems nowdays.
in VB I defined a table m_tabTagSpy() as GWC_TAG_SPY_INFOS
Let say I want 10 Tags : redim m_tabTagSpy(10)
I call m_pIServerLorCom.GetTagSpy 10, lgRealSize, m_tabTagSpy(0)
In return I only have the first value filled, when I check in debug, the C++ fill the all structure whithout exception, but returning the hand to the VB and every datas are lost !!!
Moreover if I ask the values one by one, I have big memory leaks but I don't know where.
If anyone could help I would be very grateful.
Matt.
|
|
|
|
|
Since you're working with VB, you're best off with an Automation-compatible interface. I would recommend using a SAFEARRAY of your structure.
Your problem is stemming from the Automation marshaller not knowing that you actually want an array; it therefore does not marshal the data appropriately across the process boundary.
See this article[^] for information on how to use arrays of user-defined types in COM objects.
|
|
|
|
|
Hello everyone,
I’m starting on a new project. My major task is to create vb.net application using the existing com component which is created with MFC (I think it is kind of com component created and based on the c code).
I searched a lot of materials from internet and found all the examples are kind of vb.net call the com component created with vb6 (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callcomcomp.asp) and c application call the com component created with c code (http://www.codeproject.com/com/comintro.asp).
Could you tell me is that possible to create vb.net application calling the com component created with MFC (Kind of C code). Do you have an example on how to do it?
Thank you very much for your any information in advance
Jane
|
|
|
|
|
I have created a COM+ component in VB.NET. This is a class library using factoring compiled into a dll file (MHC_ES.dll). This file references a C++ dll called "vb.dll". This is on a Windows Server 2003 using a Windows XP (eventually Windows 2000 to be used) client.
The problem is, when I have the service started on the server, the COM+ solution attached to the correct process, run the client, and get to one of the COM+ functions, it does not step into the breakpointed code on the server (COM+ solution open). I also get an error saying "Unable to load DLL (vb.dll)" - not the COM+ dll component, but the C++ dll it refers to.
The following code and methods are used to create the component service:
<assembly: applicationname("vbdll_es")="">
<assembly: descriptionattribute("vbdll_remoting="" component")="">
<assembly: applicationactivation(activationoption.library)="">
<assembly: assemblykeyfile("vbdll_es.snk")="">
<transaction(transactionoption.required), _
justintimeactivation(true),="" _
objectpooling(enabled:="True," minpoolsize:="2," maxpoolsize:="10)," _
constructionenabledattribute(default:="Server=192.168.0.46;Integrated Security=SSPI" )=""> _
Public Class vbdll_remoting
Inherits ServicedComponent
Public Shared attrs() As Object = {New System.Runtime.Remoting.Activation.UrlAttribute("tcp://192.168.0.46:50000/vbdll_remoting.rem")}
Public Shared instance As vbdll_remoting = Nothing
Public Shared Function get_instance() As vbdll_remoting
Dim intInput As Integer
If (instance Is Nothing) Then
Try
instance = New vbdll_remoting
Return instance
Catch ex As Exception
MsgBox(ex.Message & vbCrLf & vbCrLf & "'vbdll_remoting.get_instance' failed.")
End Try
End If
End Function
<autocompleteattribute(true)> _
Public Sub remote_check()
'See if App is up and running.
End Sub
End Class
' And a module here referring to vb.dll (C++ compiled dll)
' functions.
Imports System.Runtime.InteropServices
Module vbdll_ext
' /*** DLL test functions***/
<dllimport("vb.dll")> _
Public Sub vb_set(ByVal str_Renamed As String)
End Sub
' Other references to vb.dll (C++ compiled dll)
End Module
I use the following methods:
1. gacutil -i MHC_ES.dll
2. regsvcs.exe MHC_ES.dll
3. open Component Services
4. find corresponding COM+ component
5. open properties
6. Activation tab, change to Server Application
7. press "Apply"
8. check "Run application as NT Service"
9. go to Advanced tab
10. check Debugging "Launch in debugger"
11. OK and close properties
12. export as .MSI and install on client
13. refer to MHC_ES class on client
14. Start the component service on server
15. Open COM+ VB.NET solution on server
16. Go to Debug on menu and attach to appropriate process which appears as DllHost.exe
17. Run app on Client (Windows XP on network to Windows Server 2003)
18. Step to point at which it calls COM+ function
The breakpoint set in the COM+ VB.NET solution does not catch, and the "Unable to load DLL (vb.dll)" comes up.
I've been trying lots of things, but cannot get it to step into the COM+ code on the server side. I have run the client app on the Windows 2003 server itself. It will step into the COM+ code, but as soon as it hits the vb.dll function, it hangs. This vb.dll is a legacy dll that has been working fine.
In fact, using .NET remoting in stead of COM+, the stepping into the server side code was working fine! Including into the vb.dll C++ generated code. There were just other mysterious problems (crashing) running over night, so I wanted to give COM+ a try.
Any help appreciated! (Hope I didn't give anyone a headache ...)
Bryan
|
|
|
|
|
Been working on this - main problem now is "Unable to load DLL (vb.dll)". The COM+ object seems to work properly because I can see it running on the Client and Server, and I do a database call from Client to Server and the Client retrieves the appropriate data from the Server.
But when a call is made to the unmanaged C++ "vb.dll", it says "Unable to load DLL (vb.dll)".
So how do I enable the COM+ object to find or load the unmanaged DLL? I have put the vb.dll in the Windows/system32 folder - I have put it in the corresponding project folder.
Code is simply:
' /*** DLL test functions***/
<dllimport("vb.dll")> _
Public Sub vb_set(ByVal str_Renamed As String)
End Sub
Changing "vb.dll" to include path "C:/folder/vb.dll" will just cause error to read "Unable to read DLL ("C:/folder/vb.dll").
Help!
|
|
|
|
|
Could somebody tell me that in a Java application,how to call methods in a COM component?
William
|
|
|
|
|
Java provides JNI - java native interface. this is the only way to communicate between Java - Win32 paltfoprms. But JNI needs win32 components as pure win32 dlls and it doesnt understand COM components. So write a win32 dll wrpper over the com component and use it.
cheers..Milton KB
|
|
|
|
|
Thank you so much for your help. But I really need a simple way to call a method in a COM object from a Java application.
William
|
|
|
|
|
|