Click here to Skip to main content
14,361,747 members
   

C#

 
QuestionHow to determine the real font size? Pin
Frank Horn18-Jul-08 4:35
memberFrank Horn18-Jul-08 4:35 
QuestionQuestion regarding memory garbage collection in C# from COM C++ Pin
Green Fuze18-Jul-08 3:13
memberGreen Fuze18-Jul-08 3:13 
AnswerRe: Question regarding memory garbage collection in C# from COM C++ Pin
Guffa18-Jul-08 3:50
memberGuffa18-Jul-08 3:50 
GeneralRe: Question regarding memory garbage collection in C# from COM C++ Pin
Green Fuze19-Jul-08 2:32
memberGreen Fuze19-Jul-08 2:32 
AnswerRe: Question regarding memory garbage collection in C# from COM C++ Pin
CPallini18-Jul-08 4:00
mveCPallini18-Jul-08 4:00 
GeneralRe: Question regarding memory garbage collection in C# from COM C++ Pin
Green Fuze19-Jul-08 2:29
memberGreen Fuze19-Jul-08 2:29 
GeneralYou're welcome Pin
CPallini19-Jul-08 10:08
mveCPallini19-Jul-08 10:08 
AnswerRe: Question regarding memory garbage collection in C# from COM C++ Pin
Mike Dimmick18-Jul-08 7:31
memberMike Dimmick18-Jul-08 7:31 
Whenever you allocate memory in a COM component that you intend to return to the caller, you should use COM's memory allocator, which you can obtain by calling CoGetMalloc. There's a straightforward wrapper for allocation called CoTaskMemAlloc, which has the counterparts CoTaskMemRealloc for increasing the block's size, and CoTaskMemFree for freeing memory allocated this way.

The COM runtime will have to manage memory for you any time it passes any kind of boundary, so you should always do this even with C++ clients and servers. It's a good idea to do it properly

In your IDL, you will need to provide attributes to tell the marshalling layer what pointers actually mean. Do these point to one byte, or to an array of bytes? If it's an array, you'll need to provide information about whether it's null terminated ([string]) or what the size of the array is ([size_is]).

If you mean one byte, the runtime will be expecting the caller to pass a pointer to a location where the byte should be stored, and the called function should write directly to that address without allocating.

If you really mean passing in one byte and returning one byte, I'd write it:
void do_something(byte input, [out] byte* output);
[out] just tells MIDL that the value is an output and doesn't need to be marshalled on the 'in' direction (this means the function will receive junk data). I've changed the first parameter to a single byte passed by value.

In addition you should really make the return type HRESULT. This is the only way to signal faults; if a failure HRESULT is returned, the .NET marshalling layer will throw the corresponding exception.


DoEvents: Generating unexpected recursion since 1991

GeneralRe: Question regarding memory garbage collection in C# from COM C++ Pin
Green Fuze19-Jul-08 2:27
memberGreen Fuze19-Jul-08 2:27 
QuestionVStudio refuses to start a solution Pin
Tomerland18-Jul-08 2:45
memberTomerland18-Jul-08 2:45 
AnswerRe: VStudio refuses to start a solution Pin
Fredrik Bornander18-Jul-08 3:53
professionalFredrik Bornander18-Jul-08 3:53 
AnswerRe: VStudio refuses to start a solution Pin
Guffa18-Jul-08 3:56
memberGuffa18-Jul-08 3:56 
GeneralRe: VStudio refuses to start a solution Pin
Tomerland18-Jul-08 4:56
memberTomerland18-Jul-08 4:56 
Questionprogress window Pin
Mogaambo18-Jul-08 2:23
memberMogaambo18-Jul-08 2:23 
AnswerRe: progress window Pin
N a v a n e e t h18-Jul-08 2:32
memberN a v a n e e t h18-Jul-08 2:32 
GeneralRe: progress window Pin
Mogaambo18-Jul-08 2:38
memberMogaambo18-Jul-08 2:38 
GeneralRe: progress window Pin
enginço18-Jul-08 2:43
memberenginço18-Jul-08 2:43 
GeneralRe: progress window Pin
N a v a n e e t h18-Jul-08 2:46
memberN a v a n e e t h18-Jul-08 2:46 
GeneralRe: progress window Pin
Mogaambo18-Jul-08 2:51
memberMogaambo18-Jul-08 2:51 
GeneralRe: progress window Pin
N a v a n e e t h18-Jul-08 3:05
memberN a v a n e e t h18-Jul-08 3:05 
GeneralRe: progress window Pin
Mogaambo18-Jul-08 3:34
memberMogaambo18-Jul-08 3:34 
GeneralRe: progress window Pin
N a v a n e e t h18-Jul-08 3:45
memberN a v a n e e t h18-Jul-08 3:45 
GeneralRe: Please check only that lines which are commented AND IGNORE REST Pin
Mogaambo18-Jul-08 3:52
memberMogaambo18-Jul-08 3:52 
GeneralRe: Please check only that lines which are commented AND IGNORE REST Pin
N a v a n e e t h18-Jul-08 4:05
memberN a v a n e e t h18-Jul-08 4:05 
GeneralRe: Please check only that lines which are commented AND IGNORE REST Pin
Mogaambo18-Jul-08 4:14
memberMogaambo18-Jul-08 4:14 

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.