473,320 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ref or out parameter in delegate, declared in C++

Hello,

I am trying to declare in C++ and use in C# a delegate which contains
"ref" and "out" parameters.

I declare a delegate as:

public __delegate void SolFSCreateFileEvent(SolFSStorage* Sender,
System::String* FileName, Handle &File, bool Overwrite, bool
IsJournalFile, Error &Result);

(I also tried "[Out] Error* Result" and Error* Result, no luck).

In C# I declare a method:

public void OnCreateFile(SolFSStorage Sender, String FileName, ref UInt32
File, bool Overwrite, bool IsJournalFile, ref int Result)

and try to create an instance as

new SolFSCreateFileEvent(OnCreateFile)

What I get is compiler error:

Method 'SolFSExplorer.MainForm.OnCreateFile(SolFS.SolFSSt orage, string,
ref uint, bool, bool, ref int)' does not match delegate 'void
SolFS.SolFSCreateFileEvent(SolFS.SolFSStorage, string, uint*, bool,
bool, int*)'
If I change C# declaration to

public void OnCreateFile(SolFSStorage Sender, String FileName, UInt32
*File, bool Overwrite, bool IsJournalFile, int *Result)

then the previous error disappears but another one appears, saying that
* is only allowed in unsafe context (sounds reasonable <g>).

What can be a solution besides declaring CreateFileEventArgs helper
class and passing it as a single parameter?

Free copy of SolFS (http://www.eldos.org/solfs/solfs.html) to be given
to first person who knows a solution.

Sincerely yours,
Eugene Mayevski
Nov 15 '05 #1
3 3221
Eugene,

The solution is to declare the delegate as follows:

public __delegate void SolFSCreateFileEvent(
SolFSStorage* Sender,
System::String* FileName,
System::UInt32 __gc * File,
bool Overwrite,
bool IsJournalFile,
System::Int32 __gc * Result);

A C# ref parameter corresponds to a C++ managed pointer to a value type.

Have I won? :-)

Greetings

Bart Jacobs

Eugene Mayevski wrote:
Hello,

I am trying to declare in C++ and use in C# a delegate which contains
"ref" and "out" parameters.

I declare a delegate as:

public __delegate void SolFSCreateFileEvent(SolFSStorage* Sender,
System::String* FileName, Handle &File, bool Overwrite, bool
IsJournalFile, Error &Result);

(I also tried "[Out] Error* Result" and Error* Result, no luck).

In C# I declare a method:

public void OnCreateFile(SolFSStorage Sender, String FileName, ref UInt32
File, bool Overwrite, bool IsJournalFile, ref int Result)

and try to create an instance as

new SolFSCreateFileEvent(OnCreateFile)

What I get is compiler error:

Method 'SolFSExplorer.MainForm.OnCreateFile(SolFS.SolFSSt orage, string,
ref uint, bool, bool, ref int)' does not match delegate 'void
SolFS.SolFSCreateFileEvent(SolFS.SolFSStorage, string, uint*, bool,
bool, int*)'
If I change C# declaration to

public void OnCreateFile(SolFSStorage Sender, String FileName, UInt32
*File, bool Overwrite, bool IsJournalFile, int *Result)

then the previous error disappears but another one appears, saying that
* is only allowed in unsafe context (sounds reasonable <g>).

What can be a solution besides declaring CreateFileEventArgs helper
class and passing it as a single parameter?

Free copy of SolFS (http://www.eldos.org/solfs/solfs.html) to be given
to first person who knows a solution.

Sincerely yours,
Eugene Mayevski


Nov 15 '05 #2
Bart Jacobs wrote:

BJ> public __delegate void SolFSCreateFileEvent(
BJ> SolFSStorage* Sender,
BJ> System::String* FileName,
BJ> System::UInt32 __gc * File,
BJ> bool Overwrite,
BJ> bool IsJournalFile,
BJ> System::Int32 __gc * Result);

public __delegate void SolFSCreateFileEvent(SolFSStorage* Sender,
System::String* FileName, System::Int32 __gc * File, bool Overwrite,
bool IsJournalFile, System::Int32 __gc * Result);

Looks like the same, right (except File parameter type, but this doesn't
matter)? Here's what I get from compiler:

c:\Projects\SolFS\DotNet\DotNet.h(35): error C2144: syntax error : 'int'
should be preceded by ','
c:\Projects\SolFS\DotNet\DotNet.h(35): error C2501: 'Result' : missing
storage-class or type specifiers
c:\Projects\SolFS\DotNet\DotNet.h(36): fatal error C1903: unable to
recover from previous error(s); stopping compilation

(correction from e-mail) caret is on the first position of the line, not
indicating the exact error, but removing the last parameter (Result)
doesn't help.

This is about the above line. Any ideas? If I remove __gc, the error is the
same. So this must be something with System::Int32? But why is
System::String ok then?

Sincerely yours,
Eugene Mayevski

Nov 15 '05 #3
Eugene Mayevski wrote:
public __delegate void SolFSCreateFileEvent(SolFSStorage* Sender,
System::String* FileName, System::Int32 __gc * File, bool Overwrite,
bool IsJournalFile, System::Int32 __gc * Result);


Must be public __delegate void SolFSCreateFileEvent(SolFSStorage*
Sender, System::String* FileName, UInt32 __gc &FileHandle, bool
Overwrite, bool IsJournalFile, Int32 __gc &Result);

But as your tip really helped, please contact me for the license and
give me the name and e-mail for registration record.

--
Eugene Mayevski
EldoS Corp., CTO
Networking and security solutions, custom development services
http://www.eldos.com

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: yoramo | last post by:
hello can I pass a static method as a parameter to a method? if the answer is yes how do I do that ? how do I call the method ? yoramo.
0
by: Alex Zhitlenok | last post by:
I found out that if you subscribe to or unsubscribe from an event in the method that gets event handler as a parameter, it does not work as expected. If the event is declared as event...
21
by: vmsgman | last post by:
Here is a code sample ... int blah = ReadFile( defArray, defFileName, w, h); // Read File Contents into memory array and return for processing public int ReadFile( ref ushort nArray, string...
3
by: Eugene Mayevski | last post by:
Hello, I am trying to declare in C++ and use in C# a delegate which contains "ref" and "out" parameters. I declare a delegate as: public __delegate void SolFSCreateFileEvent(SolFSStorage*...
7
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a...
4
by: Anthony Coelho | last post by:
Hello Guru's! I am trying to pass a function pointer as a parameter to a method and can't seem to get it working. Basically I want to do the exact same thing that the System.Threading.Thread...
5
by: Amit Bansal \(MCT, MCSD.NET\) | last post by:
What is meant by this statement? "Although the delegate can use an out parameter, it is not recommended to use it with multicast event delegates because there is no way to know which delegate...
6
by: =?Utf-8?B?emlubw==?= | last post by:
I'm trying to pass a delegate as parameter but the code below does not compile. It display an error: 'AddressOf operand must the name of a method(without parantheses)' How can I make it work. ...
10
by: vcquestions | last post by:
Hi. Is there way to have a function pointer to a delegate in c++/cli that would allow me to pass delegates with the same signatures as parameters to a method? I'm working with managed code. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.