Click here to Skip to main content
15,895,799 members
Home / Discussions / C#
   

C#

 
QuestionHow to determine the real font size? Pin
Frank Horn18-Jul-08 3:35
Frank Horn18-Jul-08 3:35 
QuestionQuestion regarding memory garbage collection in C# from COM C++ Pin
Green Fuze18-Jul-08 2:13
Green Fuze18-Jul-08 2:13 
AnswerRe: Question regarding memory garbage collection in C# from COM C++ Pin
Guffa18-Jul-08 2:50
Guffa18-Jul-08 2:50 
GeneralRe: Question regarding memory garbage collection in C# from COM C++ Pin
Green Fuze19-Jul-08 1:32
Green Fuze19-Jul-08 1:32 
AnswerRe: Question regarding memory garbage collection in C# from COM C++ Pin
CPallini18-Jul-08 3:00
mveCPallini18-Jul-08 3:00 
GeneralRe: Question regarding memory garbage collection in C# from COM C++ Pin
Green Fuze19-Jul-08 1:29
Green Fuze19-Jul-08 1:29 
GeneralYou're welcome Pin
CPallini19-Jul-08 9:08
mveCPallini19-Jul-08 9:08 
AnswerRe: Question regarding memory garbage collection in C# from COM C++ Pin
Mike Dimmick18-Jul-08 6:31
Mike Dimmick18-Jul-08 6: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 1:27
Green Fuze19-Jul-08 1:27 
QuestionVStudio refuses to start a solution Pin
Tomerland18-Jul-08 1:45
Tomerland18-Jul-08 1:45 
AnswerRe: VStudio refuses to start a solution Pin
Fredrik Bornander18-Jul-08 2:53
professionalFredrik Bornander18-Jul-08 2:53 
AnswerRe: VStudio refuses to start a solution Pin
Guffa18-Jul-08 2:56
Guffa18-Jul-08 2:56 
GeneralRe: VStudio refuses to start a solution Pin
Tomerland18-Jul-08 3:56
Tomerland18-Jul-08 3:56 
Questionprogress window Pin
Mogaambo18-Jul-08 1:23
Mogaambo18-Jul-08 1:23 
AnswerRe: progress window Pin
N a v a n e e t h18-Jul-08 1:32
N a v a n e e t h18-Jul-08 1:32 
GeneralRe: progress window Pin
Mogaambo18-Jul-08 1:38
Mogaambo18-Jul-08 1:38 
GeneralRe: progress window Pin
enginço18-Jul-08 1:43
enginço18-Jul-08 1:43 
GeneralRe: progress window Pin
N a v a n e e t h18-Jul-08 1:46
N a v a n e e t h18-Jul-08 1:46 
GeneralRe: progress window Pin
Mogaambo18-Jul-08 1:51
Mogaambo18-Jul-08 1:51 
GeneralRe: progress window Pin
N a v a n e e t h18-Jul-08 2:05
N a v a n e e t h18-Jul-08 2:05 
GeneralRe: progress window Pin
Mogaambo18-Jul-08 2:34
Mogaambo18-Jul-08 2:34 
GeneralRe: progress window Pin
N a v a n e e t h18-Jul-08 2:45
N a v a n e e t h18-Jul-08 2:45 
GeneralRe: Please check only that lines which are commented AND IGNORE REST Pin
Mogaambo18-Jul-08 2:52
Mogaambo18-Jul-08 2: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 3:05
N a v a n e e t h18-Jul-08 3:05 
GeneralRe: Please check only that lines which are commented AND IGNORE REST Pin
Mogaambo18-Jul-08 3:14
Mogaambo18-Jul-08 3: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.