|
Yes, use sizeof(YourStruct). If you have embedded structs, you're going to have to be more creative e.g.
sizeof(YourStruct) + (sizeof(YourEmbeddedStruct) * NumberOfEmbeddedStructs)
etc.
It can get tricky if your structs contain "variable" data, such as strings. In the past, I've either defined the maximum size of the string (and therefore constrained the array inside the struct definition) or I've added a counter then a pointer, e.g.
...
unsigned long ByteCount;
unsigned char* pByteData;
};
The count tells the caller how big the variable data is. Hope that helps.
|
|
|
|
|
Why do that, when you can define the structure in IDL?
--
Look straight into the light!
|
|
|
|
|
Yep, that's perfectly valid (and arguably the "right" way) but then you have an extra step of publishing the interface and managing proxy stubs. My way keeps things simple and flexible.
|
|
|
|
|
Because my structs contain, in some cases, arrays, that have to be defined as SAFEARRAYS.
In any case, I implemented this way... I will debug the application when I will resolve my new problems (It's since a month that, when I manage to resolve a strange problem, there comes in another problem, even stranger, if possible! )
If you're curious, look above....
Thanks again,
Morenz
|
|
|
|
|
Hi,
I'm a newbie in COM development. I need to open a file of a particular format,other the ones supported by IE like .doc,.txt,.PDF etc, in the IE.
e.g. if the file is say, a.x, of a particular format, the "Open With : IE" will open the file in the IE browser window, much like the case of .pdf file.
I browsed a lot, such as, BHO etc. but could not find a proper solution.
So, I need this very urgently....
Regards,
babai.
-- modified at 12:37 Thursday 29th September, 2005
|
|
|
|
|
I have a COM object that throws an event with a collection of others COM objects. I’m not sure about the way I have to do it. The code I have implemented is like....
ICollection * pInterfaceCollection;<br />
CCollection * pCollection = new CCollection (<COM objects array>);<br />
pCollection->QueryInterface(IID_ICollection, (void**) &pInterfaceCollection);<br />
pInterfaceCollection->Release();<br />
<br />
result = Fire_OnColletionItems(pInterfaceCollection);<br />
if(FAILED(result))<br />
{<br />
... <br />
}
The problem here is that I have memory leaks. I fire the event, the client (an VB application) manages it, I shut down the client, and then I shut down my application (the server)... and there they are. I thought that the client was who release the object so I shouldn’t do it. How should I to do this?
Thank you in advance.
PD: sorry for my english
-- modified at 13:54 Tuesday 27th September, 2005
|
|
|
|
|
I'm working on an object that crosses two systems (one system uses standard CPropertyPages for all its objects, the other uses COM/ATL IPropertyPageImpl<t>)
The standard system objects simply create a property sheet and invoke DoModal() while the other uses OleCreatePropertyFrame() for its pages.
How do you launch a mixed collection of both systems? (CPropertyPages with COM/ATL ones)
Thanks in advance for advice!
|
|
|
|
|
DolphLundgren wrote:
How do you launch a mixed collection of both systems? (CPropertyPages with COM/ATL ones)
I don't know exactly how CPropertyPages work, so maybe what I'm about to suggest is just not doable. If so, then I appologize.
I suppose you could inherit a new class from CPropertyPage, in which you host the COM property page, and mediates between the COM interfaces (IPropertyPage and IPropertyPageSite) and the CPropertyPage interface.
What you need to think about when creating the COM property page is:
* Your class based on CPropertyPage must implement IPropertyPageSite
* After you've created the IPropertyPage object, call SetPageSite(this)
* Give the COM object to the prop page object by using SetObjects()
* Then call Activate(m_hWnd, rcTheRectangle, FALSE)
* Followed by Show(SW_SHOW) (I think this is necessary - I don't remember - you'll notice)
IPropertyPageSite is straightforward to implement. Please refer to the MSDN docs.
Call the prop page object's Apply() method when suitable (probably on some well defined OnApply()-event defined for CPropertyPage).
When you are closing down the CPropertyPage window, call the prop page object's Deactivate() method.
--
Keep talking! You're the fool, I'm the preacher.
|
|
|
|
|
Hi all,
does any one know that how can I switch between two DLLs
dynamically based on some condition.
What I want to achieve is that I have an application which has to call
some functions in a C++ library exposed as a DLL.
Now I have two versions of this library which export the almost the
same symbols (not exactly the same thus different .libs for them) but I
want to allow the application to switch between these two DLL's
dynamically so that whenever it wishes it can call one library or the
other as per the need.
Remember I cannot link with both the libraries because they both
contain almost the same symbols. The sample scenario is shown below:
app --- links with EITHER DLL1
--- OR links with DLL2
DLL1 -- exports say symbols - a,b,c
DLL2 -- exports say symbols - b,c,d
app decides dynamically at runtime
if(condition 1)
Load DLL1
call a;
...
else
Load DLL2
call b;
call c;
...
I hope my question is clear.
Thanks in advance,
Divick
|
|
|
|
|
cant you use LoadLibrary(),freelibrary() ?
|
|
|
|
|
Well, to clarify my question more, I don't want to do a LoadLibrary within the application. What I want is that the application shouldn't know at all which DLL it is loading but there may be additional DLL or COM component in between which can decide which particular DLL to load and then load the DLL automatically.
Waiting for suggestions/ tips/ comments.
Thanks,
Divick
|
|
|
|
|
Does nobody has a solution for this or my question is too cryptic?
Any suggestions/ideas are welcome.
Thanks a ton,
Divick
|
|
|
|
|
The best way I know of to do this is
1) Define an interface that provides standard definitions of the DLL functions you need to call. Your application should only work with the interfaces - that way it does not need to know anything about how the interface functions are actually implemented.
2) Create a wrapper class for each DLL that actually implements the interface function calls you defined in step 1.
3) Create the code needed to instantiate the correct class you created in Step 2, depending on which DLL you want to use. Usually you create an Abstract Factory pattern to accomplish this, but if your cases are simple enough, you may just use a function with a Select Case construction.
COM allows instantiated by the CreateObject(ComponentName.ClassName) method, so if done properly, you can completely decouple the main application from both the intermediate wrapper DLLs as well as the DLL you want to load dynamically, so you no longer have a linking conflict.
|
|
|
|
|
Did anyone tried event handling on activex controls from Grid present on property sheet provided by MFC ActiveX control wizard.
If yes can anyone let me how can this be done
-- modified at 5:26 Friday 30th September, 2005
|
|
|
|
|
Hi everybody,
I use a ITypeLib object and a ITypeInfo objects to get the method parameter types by the mean of GetFuncDesc. But how can I get the parameter name?
Thanx for reading my post,
BR
|
|
|
|
|
Hello mpuerto,
Use the ITypeInfo::GetNames() method. E.g. :
typedef std::vector<BSTR> BSTR_VECTOR;
...
...
...
BSTR_VECTOR vecFunctionParameters;
pITypeInfo -> GetFuncDesc
(
(unsigned int)function_id,
(FUNCDESC FAR* FAR*)&pFUNCDESC
);
// Resize the vector of BSTRs to hold "cParams + 1" number
// of parameters. We plus 1 because GetNames() will return
// to us the name of the method itself as the first returned
// name.
vecFunctionParameters.resize(pFUNCDESC->cParams + 1);
pITypeInfo -> GetNames
(
(MEMBERID)(pFUNCDESC->memid),
(BSTR FAR*)&(vecFunctionParameters[0]),
(unsigned int)(pFUNCDESC->cParams + 1),
(unsigned int FAR*)&cNames
);
BSTR_VECTOR::iterator theIterator;
DWORD dwParamIndex = 0;
for
(
theIterator = (vecFunctionParameters.begin() + 1), dwParamIndex = 0;
theIterator != vecFunctionParameters.end();
theIterator++, dwParamIndex++
)
{
BSTR bstrTemp = (BSTR)(*theIterator);
_bstr_t _bstTemp(bstrTemp, true);
TYPEDESC td = ((pFUNCDESC->lprgelemdescParam) + dwParamIndex)->tdesc;
std::cout << (LPCTSTR)_bstTemp << " " << td.vt << std::endl;
::SysFreeString(bstrTemp);
bstrTemp = NULL;
}
Give it a try, mpuerto.
Best Regards,
Bio.
|
|
|
|
|
Thank you very much for your help!!
That's what I needed. You've got a 5 from me. You have saved my life.
Thanks also to everybody who at least read my post.
BR,
mpuerto
|
|
|
|
|
hi there,
i got a problem when switching my apartment modell from single-threaded to multi-threaded (using c#).
i make use of the DragDropHelper interface, which (as far as i know) has to be initialized via "CoCreateInstance" as "CLSCTX.INPROC_SERVER"; however, when i switch to MTAThread for a multithreaded department, the instantiation fails saying something like "interface not supported" (or "class not registered" as i played around with the CLSCTX-parameter).
the thing is, i make extensive use of COM-interfaces as i write some kind of explorer-replacement; as doing so some functions are really slow (like icon extraction on tons of files ), i decided to switch to the multithreaded-department; however, some COM-interfaces aren't supported there (e.g. IShellIcon) when trying to instanciate in a STAThread department but trying to use in a seperate thread...
my opinion was, switching to MTAThread-department would let me allow to use COM in seperate threads, however, DragDropHelper-instanciation fails although doing in the main thread of the process.
Any ideas, did i miss something?
regards,
tajbender
|
|
|
|
|
I'm building an MFC app to view tv guide information; just for fun. In
this app I need a grid-like control. I have experimented with MSFlexGrid
and don't really care for it. I have ideas to create my own control with
variable length cells on a row (array style v. columns) and I would like
to add some fancy gradiant shading, images, hovertext, and some other
things.
Anyway, I wanted to implement the grid as an ActiveX control but am having
trouble getting CScrollBar to work. I have written ActiveX controls before
which had CDialog based popups. In this case I'm thinking CScrollView might
be better since I don't want a popup. I actually have most of it written
simply using CBrush, CFont, and CRect in the OnDraw event. If I could just
get a CScrollBar to show up and send event messages I'd be on my way.
I'd like this to be as lightweight as possible. It appears that using
CScrollView would require an SDI/MDI class and I'm not really sure how to
add this to an ActiveX control or if I event want to. If it's not a
lightweight control I'd almost rather just build this into my main
project.
So I'm looking for design advice and/or links to web pages demonstrating
adding MFC common controls to an ActiveX ocx and mapping the messages. I
found HOWTO: Add Tooltips to ActiveX controls in the MSDN library which
I am going to try but its not really what I want.
Thanks.
dwh
|
|
|
|
|
There is an article on codeguru (http://www.codeguru.com/Cpp/misc/misc/article.php/c6093/[^]) about using active scripting with MFC or ATL/WTL application. The code library instruments connection points between VBScript and host application so one can call C/C++ functions from VBScript and share the variables between the two. The implementation is reasonable except one issue, It suffer from an “Interface Leak”. One can see the leak running the sample program with the article in debug mode.
It seems the AddRef()/Release() are not balanced in the code. I was curios to see where the bug was. Tracing the interface code, it seems that “QueryInterface()” is seemingly adding implicit reference on the interface.
I fixed the problem by inserting an extra Release() on pIDisp on line 308 in file “ScriptHost.cpp” after the AddRef(). It seemingly solves the problem with no more interface leaks.
The fix above is for function residing in the application, the same fix on couple of lines above solves the shared variable issue too.
I am curious to get some input from COM gurus why a call to QueryInterface() is adding an extra reference on the interface.
|
|
|
|
|
mango_lier wrote:
I am curious to get some input from COM gurus why a call to QueryInterface() is adding an extra reference on the interface.
The COM rules says explicitly that a successful QueryInterface shall increase the reference count. This must be the case if you think about it. You are getting a reference to a new interface handle. It must be AddRef()'d because of situations like these:
IUnknown* pUnk = ...;
IMyInterface* pItf;
pUnk->QueryInterface(__uuidof(IMyInterface), (void**)&pItf);
pUnk->Release();
pItf->MyMethod(); If QueryInterface didn't AddRef(), then the code above would be invalid.
The COM rules assures that client code does not need to be complex.
Good music: In my rosary[^]
-- modified at 5:20 Sunday 25th September, 2005
|
|
|
|
|
Give me an Example of Custom marshelling in COM.
Bhargava Alanka
|
|
|
|
|
Hi every one !
Dear i m doing a project that i want to transfer text,audio,video data between two web application.if any one can help me in this regard i will be very thankfull to you.
Ok bye
waiting
irshad
hello join me and give me some useful information
allah hafiz
irshad
|
|
|
|
|
I need IPhelper API for one of my application ..... but MSVC installed on my system doesnt have this file or IpHelper.h .....
and quite rightly when i compile the program, it gives error
fatal error C1083: Cannot open include file: 'Iphlpapi.h': No such file or directory
I searched in my MSVC and didnt find it there..... so tell me how can i get it ...
Best regards
Mukhan
|
|
|
|
|
hi,
I am new to this , what does does this COM stands for
Can anyone send me some help regarding this
regds
Amit
|
|
|
|
|