I have a problem by developing on wp8.I want to add Microsoft advertisement to my project.
http://www.cocos2d-x.org/docs/manual/framework/native/v2/sdk-integration/wp8-thirdSDK/en
But somehow I could not successful.When I try to step ‘implement ICallback interface in c#’ that the project could not find “ICallback”,and then could not go on.Please help my how to solve this problem.Thank you.
Will someone please reply to these posts, I also posted a question related to WP8 admob integration and calling showAd from c++.
Just bumping, I’m stuck at the same point.
Here is how I make it:
In file GameHelper.h:
namespace PhoneDirect3DXamlAppComponent
{
public interface class IGameHelperCallback
{
public:
void ShowAd();
};
public ref class GameHelperDelegate sealed
{
public:
GameHelperDelegate(IGameHelperCallback^ CSharpHelper);
property static IGameHelperCallback^ Callback;
};
}
In file GameHelper.cpp:
GameHelperDelegate::GameHelperDelegate(IGameHelperCallback^ CSharpHelper)
{
Callback = CSharpHelper;
}
In file GameHelper.cs:
namespace PhoneDirect3DXamlAppInterop
{
public class GameHelper : IGameHelperCallback
{
private GameHelperDelegate m_cppHelper = null;
public GameHelper()
{
m_cppHelper = new GameHelperDelegate(this);
}
public void ShowAd()
{
// do some real work to show the ad
}
}
}
In any of your c++ files:
PhoneDirect3DXamlAppComponent::GameHelperDelegate::Callback->ShowAd();
Just some snippets. I guess it’s easy to work it out.
Hi and thanks for the reply !
I tested your code in a new Project, but the same Kind of Problem remains. When I’m trying to implement IGameHelperCallback in my C#-class the Interface and also GameHelperDelegate can not be found.
Using PhoneDirect3DXamlAppComponent works. I also added the file to HelloWorldComponent, so it should be referenced in my Solution and the .winmd file !?
Edit : Solved it… I missed to add the according .cpp-file…
Congrats!
You’re right, the cpp file should be included in the component project. I change the snippets to add a GameHelper.cpp.
Hi!
Can you tell me more?
I have 2 file( GameHelper.h and GameHelper.cpp) in HelloCppComponent project and GameHelper.cs in HelloCpp project and i having an error “The type or namespace name ‘GameHelperDelegate’ could not be found”
In my experience, the GameHelperDelegate should be declared in .h header file and implemented in a .cpp file, like what I did above. You can’t declare and implement it in a single .h file, otherwise “GameHelperDelegate could not be found” error will be prompted.
I guess you didn’t use the right namespace. Try to add “using PhoneDirect3DXamlAppComponent;” in your .cs file.
Thanks for your reply.
But i don’t understand in GameHelper.h you declare namespace PhoneDirect3DXamlAppComponent and then you call PhoneDirect3DXamlAppInterop::GameHelperDelegate::Callback->ShowAd(); in c++ file, and in my HelloWordScene file .cpp namespace PhoneDirect3DXamlAppInterop not found
Really sorry for that I wrote it wrong and made you confused. It should be PhoneDirect3DXamlAppComponent::GameHelperDelegate::Callback->ShowAd(); in c++ file. I’ve edited it to the correct.
Thanks you verry muck. It’s work fine.
I using release mode and call Debug.WriteLine in ShowAd() =_=. It’s silly!
Edit:
I implement IGameHelperCallback in MainPage class and i call banner.Visibility = Visibility.Collapsed; in showAd() function. My game has break. Can you help me?
Edit:
in ShowAd() call
Dispatcher.BeginInvoke(() =>
{
banner.Visibility = Visibility.Collapsed
});