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 SolFSCreateFile Event(SolFSStor age* 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(So lFSStorage Sender, String FileName, ref UInt32
File, bool Overwrite, bool IsJournalFile, ref int Result)
and try to create an instance as
new SolFSCreateFile Event(OnCreateF ile)
What I get is compiler error:
Method 'SolFSExplorer. MainForm.OnCrea teFile(SolFS.So lFSStorage, string,
ref uint, bool, bool, ref int)' does not match delegate 'void
SolFS.SolFSCrea teFileEvent(Sol FS.SolFSStorage , string, uint*, bool,
bool, int*)'
If I change C# declaration to
public void OnCreateFile(So lFSStorage 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 CreateFileEvent Args 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 3 3245
Eugene,
The solution is to declare the delegate as follows:
public __delegate void SolFSCreateFile Event(
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 SolFSCreateFile Event(SolFSStor age* 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(So lFSStorage Sender, String FileName, ref UInt32 File, bool Overwrite, bool IsJournalFile, ref int Result)
and try to create an instance as
new SolFSCreateFile Event(OnCreateF ile)
What I get is compiler error:
Method 'SolFSExplorer. MainForm.OnCrea teFile(SolFS.So lFSStorage, string, ref uint, bool, bool, ref int)' does not match delegate 'void SolFS.SolFSCrea teFileEvent(Sol FS.SolFSStorage , string, uint*, bool, bool, int*)'
If I change C# declaration to
public void OnCreateFile(So lFSStorage 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 CreateFileEvent Args 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
Bart Jacobs wrote:
BJ> public __delegate void SolFSCreateFile Event(
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 SolFSCreateFile Event(SolFSStor age* 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\Sol FS\DotNet\DotNe t.h(35): error C2144: syntax error : 'int'
should be preceded by ','
c:\Projects\Sol FS\DotNet\DotNe t.h(35): error C2501: 'Result' : missing
storage-class or type specifiers
c:\Projects\Sol FS\DotNet\DotNe t.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
Eugene Mayevski wrote: public __delegate void SolFSCreateFile Event(SolFSStor age* Sender, System::String* FileName, System::Int32 __gc * File, bool Overwrite, bool IsJournalFile, System::Int32 __gc * Result);
Must be public __delegate void SolFSCreateFile Event(SolFSStor age*
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
|
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 MyEventHandler myEventHandler;
you can subscribe to the event, using the construction
myEventHandler += subscriber;
but you cannot do the same by sending event handler as a parameter to
a method of the same class.
|
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 sFname, int w, int h)
{
FileStream fs = new FileStream(sFname, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
// Read data
|
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* Sender,
System::String* FileName, Handle &File, bool Overwrite, bool
IsJournalFile, Error &Result);
|
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 subroutine
Let's say theres a sub that creates buttons and I want it to receive as a parameter the address of the sub that handles the OnClick event for the button being created
How do I pass such a parameter
Thanks in advance
Richar
| |
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 constructor does in VB.NET within my own class. In
the Thread constructor, you can specify the function to run instead of
creating a ThreadStart object by using the AddressOf keyword such as; Dim
oThread As New Threading.Thread(AddressOf foo.Run)
...
|
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 will be called."
regards
AB
|
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.
Public Class CacheFactory
Delegate Function myDelegateReport(ByVal myInfoStore As
CrystalDecisions.Enterprise.InfoStore) As
System.Collections.Generic.Dictionary(Of Long, String)
|
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. Let's say we have 2 delegates:
public delegate void FirstDelegate( int i );
public delegate void SecondDelegate( int i );
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |