-
April 1st, 2011, 07:25 AM
#1
Problem implementing an interface
Hello all,
I am trying to port over some code from C# to C++ and am having a problem with one of the functions in one of the interfaces.
The original function in the interface in C# is:
void GetApplicationThreadCount(String applicationId, out Int32 totalthreads, out Int32 unfinishedThreads);
and the C# implementation:
public void GetApplicationThreadCount(String applicationId, out IntPtr totalThreads, out IntPtr unfinishedThreads)
after reading for a while about the out keyword, I thought I should convert the interface to this:
virtual void GetApplicationThreadCount(String^ applicationId, [System::Runtime::InteropServices::Out] %totalthreads, [System::Runtime::InteropServices::Out] %unfinishedThreads);
and the c++ implementation to this:
void GetApplicationThreadCount(String^ applicationId, [System::Runtime::InteropServices::Out] %totalThreads, [System::Runtime::InteropServices::Out] %unfinishedThreads)
now I put all this together in a mixed project(the code I have converted along side the original code) so I could debug as I was wtiting it, and the C++ version appeared to work when called from C#, however, I am now converting that calling code to C++ and it does not work anymore.
The calling code from C# is:
GetApplicationThreadCount(application.ApplicationId, out totalThreads, out unfinishedThreads);
and the calling code in C++:
GetApplicationThreadCount(application->ApplicationId, totalThreads, unfinishedThreads);
totalThreads and unfinishedThreads are of type IntPtr, but when I try this, the compiler keeps telling me that I havent implemented this function yet, Im not sure but think something must be wrong in the implementation,but I am at a loss as to how to fix it.
I need the code to be callable from both C# and C++.
Thanks in advance,
Richard
-
April 1st, 2011, 07:51 AM
#2
Re: Problem implementing an interface
This isn't meant to be part of a COM interface, is it? Then there's no need for the [Out] attribute. So this should do:
Code:
virtual void GetApplicationThreadCount(String^ applicationId, Int32 %totalthreads, Int32 %unfinishedThreads);
The % already expresses what the out keyword in C# does.
Also, I don't see any reason to use IntPtr in your post but maybe I missed something. Note that IntPtr and Int32 are only (more or less) equivalent in a 32-bit environment.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
April 1st, 2011, 08:31 AM
#3
Re: Problem implementing an interface
No, this isnt for a com interface. I was just trying to make the code as exact to the C# code in c++ as I could since the C# code allready worked for the most part.
I have the signature in the interface and the implementation exactly as shown below, however, the compiler still says I dont have it implemented. Am I supposed to have virtual in both the interface and the implementation? do I need to follow the implementation with the override keyword? I tried all this with and without those keywords, I copied and pasted the interface code into the implementation definition just in case I mistyped something that I am not seeing but Im still at a loss.
Code:
virtual void GetApplicationThreadCount(String^ applicationId, Int32 %totalthreads, Int32 %unfinishedThreads);
by the way, this is the error Im getting:
Error C3766: 'Alchemi::Manager::Storage::InMemoryManagerStorage' must provide an implementation for the interface method
'void Alchemi::Core::Manager::Storage::IManagerStorage::GetApplicationThreadCount(System::String ^,int %,int %)' c:\programming\c++ version\working dir\mymanager\mymanager\MyManager.h 1302
Last edited by AKRichard; April 1st, 2011 at 08:34 AM.
-
April 1st, 2011, 08:38 AM
#4
Re: Problem implementing an interface
never mind, I just copied and pasted the definition from the interface to the implementation again and it worked, I must of screwed up the first time I did it.
Thanks for the help,
Richard
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|