Click here to Skip to main content
15,903,201 members
Home / Discussions / COM
   

COM

 
GeneralCOM interface: EnumFormatEtc Pin
Tristan Rhodes23-Dec-03 8:46
Tristan Rhodes23-Dec-03 8:46 
GeneralRe: COM interface: EnumFormatEtc Pin
Stefan Pedersen27-Dec-03 10:59
Stefan Pedersen27-Dec-03 10:59 
GeneralRe: COM interface: EnumFormatEtc Pin
Jörgen Sigvardsson6-Jan-04 6:25
Jörgen Sigvardsson6-Jan-04 6:25 
GeneralRegister an exe COM server Pin
User 78226222-Dec-03 22:58
professionalUser 78226222-Dec-03 22:58 
GeneralRe: Register an exe COM server Pin
valikac26-Dec-03 5:39
valikac26-Dec-03 5:39 
Generalextern "C" DllExport Function crashing Pin
Kishor Morkhandikar22-Dec-03 19:56
Kishor Morkhandikar22-Dec-03 19:56 
GeneralRe: extern "C" DllExport Function crashing Pin
Sebastián Benítez23-Dec-03 0:24
Sebastián Benítez23-Dec-03 0:24 
GeneralRe: extern "C" DllExport Function crashing Pin
Lim Bio Liong26-Dec-03 20:17
Lim Bio Liong26-Dec-03 20:17 
Hello Kishor,

Usage of CStrings in an exported function is perfectly fine as far as I know. Your function is declared as :

extern "C" DllExport const char* ActivatePlot(CString szPlot);

This means that when your ActivatePlot() is called, MFC creates a temporary CString for szPlot to be used within the context of the ActivatePlot() function.

Now, if this input is another CString as in the following example :

CString cstr("Country road.");
ActivatePlot(cstr);

the temporary CString "szPlot" which is created and gets passed into ActivatePlot() will contain a pointer to the same string that "cstr" points to.

The reference count of the actual string ("Country road.") is incremented and "cstr" and the "szPlot" both share the same string.

It is true that when the ActivatePlot() function exits, the CString destructor is called. This is done to free the temporary CString object "szPlot".

Let's take a look at the actual source codes of the CString destructor :

CString::~CString()
// free any attached data
{
if (GetData() != _afxDataNil)
{
if (InterlockedDecrement(&GetData()->nRefs) <= 0)
FreeData(GetData());
}
}


What happens here is that the szPlot's string pointer's reference count is decremented and only if this reference count drops to zero (or negative) will the actual string be released.

In our example, if szPlot still points to the same string "Country road.", the reference count of this string in memory is decremented but the ref count will not be zero yet (cstr still holds a ref count) and no freeing is actually performed.

I believe no harm is actually done by the destructor in this sense.

Please provide more info on how you call the ActivatePlot() function as well what actually takes place in the function ActivatePlot() so that we can have a better picture of the nature of your crash.

Thanks,
Bio.
GeneralProblems passing a DISPPARAMS structure to IDispatch::Invoke Pin
Dark Magus22-Dec-03 17:39
Dark Magus22-Dec-03 17:39 
GeneralRe: Problems passing a DISPPARAMS structure to IDispatch::Invoke Pin
Vi223-Dec-03 23:36
Vi223-Dec-03 23:36 
GeneralRe: Problems passing a DISPPARAMS structure to IDispatch::Invoke Pin
Dark Magus25-Dec-03 11:34
Dark Magus25-Dec-03 11:34 
GeneralRe: Problems passing a DISPPARAMS structure to IDispatch::Invoke Pin
Vi225-Dec-03 19:21
Vi225-Dec-03 19:21 
GeneralRe: Problems passing a DISPPARAMS structure to IDispatch::Invoke Pin
Dark Magus26-Dec-03 10:03
Dark Magus26-Dec-03 10:03 
Generalabout LocalServer COM Register Pin
yingkou22-Dec-03 15:05
yingkou22-Dec-03 15:05 
GeneralRe: about LocalServer COM Register Pin
User 78226222-Dec-03 23:16
professionalUser 78226222-Dec-03 23:16 
GeneralRe: about LocalServer COM Register Pin
Vi223-Dec-03 23:29
Vi223-Dec-03 23:29 
GeneralCOM Apartments and Marshalling Pin
Jörgen Sigvardsson22-Dec-03 14:03
Jörgen Sigvardsson22-Dec-03 14:03 
GeneralNo, that sucked Pin
Jörgen Sigvardsson23-Dec-03 7:07
Jörgen Sigvardsson23-Dec-03 7:07 
GeneralRe: No, that sucked Pin
geo_m30-Dec-03 0:32
geo_m30-Dec-03 0:32 
GeneralAll COM that expose a specific interface Pin
IreneVassileva22-Dec-03 0:00
IreneVassileva22-Dec-03 0:00 
GeneralRe: All COM that expose a specific interface Pin
Abhishek Srivastava22-Dec-03 1:01
Abhishek Srivastava22-Dec-03 1:01 
GeneralYahoo messenger login interface. Urgent Pin
SiddharthAtw21-Dec-03 18:35
SiddharthAtw21-Dec-03 18:35 
QuestionHow to access COM objects during runtime? Pin
dapipi21-Dec-03 17:13
dapipi21-Dec-03 17:13 
AnswerRe: How to access COM objects during runtime? Pin
Anonymous21-Dec-03 18:47
Anonymous21-Dec-03 18:47 
AnswerRe: How to access COM objects during runtime? Pin
Anonymous21-Dec-03 18:52
Anonymous21-Dec-03 18:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.