Developing in C# possible? - Windows Phone 7 General

I have no knowledge of Silverlight or XNA, I downloaded the Development tools, but I want to know if its possible to develop in C# even though it wont be native.............
thanx in advance

just for your understanding you can never code native with C# - therefore you'd need C/C++.
Silverlight and XNA development on WP7 is only supported in C# initially so it seems you're all ready!
didn't you check the code sample included in the Devtools?

RAMMANN said:
just for your understanding you can never code native with C# - therefore you'd need C/C++.
Silverlight and XNA development on WP7 is only supported in C# initially so it seems you're all ready!
didn't you check the code sample included in the Devtools?
Click to expand...
Click to collapse
I havent checked the sample codes yet, so I can code entirely in C# no silverlight knowledge needed?

I believe, you'll need to use Expression Blend to put your code behind a fancy Silverlight UI.
Doesn't seem that hard if you follow the training school videos school at http://www.microsoft.com/design/toolbox/

it's exactly the same like you used to develop with .NETCF though you have another bag of assemblies referenced. so stuff like file/registry access or PInvoke are gone. see it yourself:
/*
Copyright (c) 2010 Microsoft Corporation. All rights reserved.
Use of this sample source code is subject to the terms of the Microsoft license
agreement under which you licensed this sample source code and is provided AS-IS.
If you did not accept the terms of the license agreement, you are not authorized
to use this sample source code. For the terms of the license, please see the
license agreement between you and Microsoft.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Devices.Sensors;
using Microsoft.Phone.Shell;
namespace AccelerometerSample
{
/// <summary>
/// This sample shows how to use the device's accelerometer
/// </summary>
public partial class MainPage : PhoneApplicationPage
{
AccelerometerSensor accelerometer;
#region Initialization
/// <summary>
/// Constructor for the PhoneApplicationPage object.
/// In this method, the Application Bar is initialized.
/// </summary>
public MainPage()
{
InitializeComponent();
ApplicationBar = new ApplicationBar();
ApplicationBar.Visible = true;
ApplicationBarIconButton startStopButton = new ApplicationBarIconButton(new Uri("/Images/startstop.png", UriKind.Relative));
startStopButton.Click += new EventHandler(startStopButton_Click);
ApplicationBar.Buttons.Add(startStopButton);
}
#endregion
#region User Interface
/// <summary>
/// Click handler for the start/stop button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void startStopButton_Click(object sender, EventArgs e)
{
// If the accelerometer is null, it is initialized and started
if (accelerometer == null)
{
// Get the default accelerometer for the device
accelerometer = AccelerometerSensor.Default;
// Add an event handler for the ReadingChanged event.
accelerometer.ReadingChanged += new EventHandler<AccelerometerReadingAsyncEventArgs>(accelerometer_ReadingChanged);
// The Start method could throw and exception, so use a try block
try
{
statusTextBlock.Text = "starting accelerometer";
accelerometer.Start();
}
catch (AccelerometerStartFailedException exception)
{
statusTextBlock.Text = "error starting accelerometer";
}
}
else
{
// if the accelerometer is not null, call Stop
try
{
accelerometer.Stop();
accelerometer = null;
statusTextBlock.Text = "accelerometer stopped";
}
catch (AccelerometerStopFailedException exception)
{
statusTextBlock.Text = "error stopping accelerometer";
}
}
}
#endregion
#region Accelerometer Event Handling
/// <summary>
/// The event handler for the accelerometer ReadingChanged event.
/// BeginInvoke is used to pass this event args object to the UI thread.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void accelerometer_ReadingChanged(object sender, AccelerometerReadingAsyncEventArgs e)
{
Deployment.Current.Dispatcher.BeginInvoke(() => MyReadingChanged(e));
}
/// <summary>
/// Method for handling the ReadingChanged event on the UI thread.
/// This sample just displays the reading value.
/// </summary>
/// <param name="e"></param>
void MyReadingChanged(AccelerometerReadingAsyncEventArgs e)
{
statusTextBlock.Text = accelerometer.State.ToString();
XTextBlock.Text = e.Value.Value.X.ToString("0.00");
YTextBlock.Text = e.Value.Value.Y.ToString("0.00");
ZTextBlock.Text = e.Value.Value.Z.ToString("0.00");
}
#endregion
}
}
Click to expand...
Click to collapse

You need Silverlight or XNA knowledge, but the language is C#! Silverlight and XNA are just the Framework to use for developing Apps...it's still C#.
dragi

silverlight is the ui aspect of your app
there are things you will need to know about silverlight to get your information from say a database to display on fields of your application.
xna is for gaming programming (gpu interfacing, its what is used for console and zune game programming).

Thanx all!
I think I understand it now.
The developing is still being done in C# but you Need knowledge of Silverlight and XNA to use those Frameworks!
I think I will start with something really simple drawing an image on the screen

Related

OpenGL ES HTC TP2

I've been beating my head against the wall on this, so it's time to ask for help.
I've ported my game engine from iPhone to Windows CE (it actually started out many years ago as a WinCE engine, so I've developed it with portability in mind). I've also maintained a Windows build (full windows) all along for development.
I'm having problems initializing OpenGL ES on the HTC Touch Pro 2. Now what is maddening is that one of the builds worked fine, but I can't reproduce that success.
For starters, I'm linking to the Vincent OGLES implementation. If I use the Vincent libGLES_CM.DLL on a Dell x50v then it renders fine using software (so it's very slow - I haven't begun to see about using the GLES lite hardware implementation on that device yet). So is using the Vincent implementation without the software renderer DLL the correct method on a device like the TP2?
I tried this OpenGL ES SDK:
http://www.khronos.org/message_boards/viewtopic.php?f=11&t=1433
But it crashes on the first call to any OGLES API (eglGetDisplay). So I assume the linker lib is not mapping correctly to the TP2's DLL.
With Vincent it is failing at eglCreateContext, which returns EGL_BAD_ATTRIBUTE. If I do not specify an attribute list (which I see is how many other implementations call that routine) then it crashes. If I send an attribute array just containing EGL_NONE then it also crashes. It has to have at least one actual attribute to not crash.
I'm using attributes that are valid, and have tried many, many combinations, but it still returns EGL_BAD_ATTRIBUTE.
Any suggestions would be greatly appreciated.
Here's the code. I've tried calling eglCreateContext before and after eglCreateWindowSurface, because I've seen implementations do it both ways, but it made no difference.
Code:
g_hMainDC = GetDC(hWnd);
EGLConfig* configs = NULL;
const EGLint configAttribs[] =
{
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
EGL_ALPHA_SIZE, EGL_DONT_CARE,
EGL_DEPTH_SIZE, 16,
EGL_STENCIL_SIZE, EGL_DONT_CARE,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_NONE
};
glesDisplay = eglGetDisplay(g_hMainDC);
if (!glesDisplay) {
return false;
}
if (!eglInitialize(glesDisplay, NULL, NULL)) {
return false;
}
EGLint num_configs = 0;
if (!eglGetConfigs(glesDisplay, NULL, 0, &num_configs)) {
return false;
}
if (num_configs==0) {
return false;
}
configs = new EGLConfig[num_configs];
eglGetConfigs(glesDisplay,configs,sizeof(EGLConfig),&num_configs);
EGLConfig config = NULL;
if (!eglChooseConfig(glesDisplay, configAttribs, &config, 1, &num_configs)) {
return false;
}
if (num_configs==0) {
return false;
}
if (config==NULL) {
return false;
}
// Let’s create our rendering context
glesContext=eglCreateContext(glesDisplay, config, EGL_NO_CONTEXT, configAttribs);
if(!glesContext) {
return false;
}
glesSurface = eglCreateWindowSurface(glesDisplay, config, hWnd, NULL);
if (!glesSurface) {
return false;
}
Okay. Finally got a handle on this. You can't pass attributes to eglCreateContext or eglCreateWindowSurface or it will always return EGL_BAD_ATTRIBUTE. It has to be an empty array or a NULL pointer.
My app was running out of memory on the stack, and it would fail in eglCreateContext. I increased the stack size in the link settings and that fixed it. I had played around with the stack size earlier, and reverted my settings because it did not appear that had anything to do with the OGL ES initialization problems I was having.
Try to google the Xperia SDK which come with workable OpenGL ES samples.

[C#Problem] SIP and AutoScroll Panel

Hello my friends,
I have created a little application for my Windows Phone 6.5 ( oOO i Like Windows Mobile, so sad that Microsoft discontinue this !).
My project run with the CF.Net 3.5 under Visual Studio 2008.
My program has one Form with a Panel on this. On this panel i have three textBox. When i go on a textbox, the SIP enable, but my Panel doesn't autoscroll in order to allow that my TextBox stay visible.
I have read a lot and a lot of thread on Internet (msdn and other), but i don't know why, it don't succes on my project : My panel doesn't autoscrool
Here is my sample code
Code:
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Gate
{
public partial class Parametres : Form
{
public Parametres()
{
InitializeComponent();
}
private void Parametres_Load(object sender, EventArgs e)
{
// enable Tap n' Hold & auto SIP for my TextBox1
SIP.Enable(this.Textbox1.Handle);
this.sip.EnabledChanged += new EventHandler(sip_EnabledChanged);
}
void sip_EnabledChanged(object sender, EventArgs e)
{
if (sip.Enabled)
{
panel1.Size = sip.VisibleDesktop.Size;
panel1.AutoScrollPosition = new Point(0, Textbox1.Bounds.Bottom - panel1.Height - panel1.AutoScrollPosition.Y);
}
else panel1.Size = this.ClientRectangle.Size;
}
}
}
I have setted my Panel to "Autoscroll = true" in Visual Studio.
What about the Dock,etc...
I think that i have forget some parameters but i'm lost.
Anyone have a solution about this ?
Thanks a lot,
Best Regards,
Nixeus

XNA -Please Help - Collide with angle object

I'm developing a mirror for lazer beam(Ball sprite). There I'm trying to redirect the laze beam according to the ration degree of the mirror(Rectangle). How can I collide the ball to the correct angle if the colliding object is with some angle(45 deg) rather than colliding back.
Here is my complete code
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace collision
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D ballTexture;
Rectangle ballBounds;
Vector2 ballPosition;
Vector2 ballVelocity;
float ballSpeed = 30f;
Texture2D blockTexture;
Rectangle blockBounds;
Vector2 blockPosition;
private Vector2 origin;
KeyboardState keyboardState;
//Font
SpriteFont Font1;
Vector2 FontPos;
private String displayText;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
ballPosition = new Vector2(this.GraphicsDevice.Viewport.Width / 2,
this.GraphicsDevice.Viewport.Height * 0.25f);
blockPosition = new Vector2(this.GraphicsDevice.Viewport.Width / 2,
this.GraphicsDevice.Viewport.Height /2);
ballVelocity = new Vector2(0, 1);
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
ballTexture = Content.Load<Texture2D>("ball");
blockTexture = Content.Load<Texture2D>("mirror");
//create rectangles based off the size of the textures
ballBounds = new Rectangle((int)(ballPosition.X - ballTexture.Width / 2),
(int)(ballPosition.Y - ballTexture.Height / 2), ballTexture.Width, ballTexture.Height);
blockBounds = new Rectangle((int)(blockPosition.X - blockTexture.Width / 2),
(int)(blockPosition.Y - blockTexture.Height / 2), blockTexture.Width, blockTexture.Height);
origin.X = blockTexture.Width / 2;
origin.Y = blockTexture.Height / 2;
// TODO: use this.Content to load your game content here
Font1 = Content.Load<SpriteFont>("SpriteFont1");
FontPos = new Vector2(graphics.GraphicsDevice.Viewport.Width - 100, 20);
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
///
private float RotationAngle;
float circle = MathHelper.Pi * 2;
float angle;
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
//check for collision between the ball and the block, or if the ball is outside the bounds of the screen
if (ballBounds.Intersects(blockBounds) || !GraphicsDevice.Viewport.Bounds.Contains(ballBounds))
{
//we have a simple collision!
//if it has hit, swap the direction of the ball, and update it's position
ballVelocity = -ballVelocity;
ballPosition += ballVelocity * ballSpeed;
}
else
{
//move the ball a bit
ballPosition += ballVelocity * ballSpeed;
}
//update bounding boxes
ballBounds.X = (int)ballPosition.X;
ballBounds.Y = (int)ballPosition.Y;
blockBounds.X = (int)blockPosition.X;
blockBounds.Y = (int)blockPosition.Y;
keyboardState = Keyboard.GetState();
float val = 1.568017f/90;
if (keyboardState.IsKeyDown(Keys.Space))
RotationAngle = RotationAngle + (float)Math.PI;
if (keyboardState.IsKeyDown(Keys.Left))
RotationAngle = RotationAngle - val;
angle = (float)Math.PI / 4.0f; // 90 degrees
RotationAngle = angle;
// RotationAngle = RotationAngle % circle;
displayText = RotationAngle.ToString();
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
spriteBatch.Begin();
// Find the center of the string
Vector2 FontOrigin = Font1.MeasureString(displayText) / 2;
spriteBatch.DrawString(Font1, displayText, FontPos, Color.White, 0, FontOrigin, 1.0f, SpriteEffects.None, 0.5f);
spriteBatch.Draw(ballTexture, ballPosition, Color.White);
spriteBatch.Draw(blockTexture, blockPosition,null, Color.White, RotationAngle,origin, 1.0f, SpriteEffects.None, 0f);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
Do you have a github repo? I would like to help out but your wording is slightly confusing. You may have to update your collision to reflect changes in the X and Y axes seperately. I can try to replicate this and PM you my solution

Getting java.lang.NoSuchFieldError with getXXXField

Hi,
I have hooked into afterHookedMethod to read some fields from an object but I'm getting java.lang.NoSuchFieldError and I don't understand why.
Say I have these files:
Code:
package com.android.demo;
public class Bar {
public boolean mBoolean;
public Bar() {
mBoolean = false;
}
}
Code:
package com.android.sample;
public class Foo {
Bar getBar() {
Bar bar = new Bar();
bar.mBoolean = true;
return bar;
}
}
And my Xposed hook:
Code:
findAndHookMethod(
"com.android.sample",
lpparam.classLoader,
"getBar",
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// This is supposed to be `bar`, right?
Object result = param.getResult();
// Throws java.lang.NoSuchFieldError: com.android.demo.Bar#mBoolean
Log.d(TAG, "mBoolean: " + String.valueOf(getBooleanField(result, "mBoolean")));
// In the end this is what I'm trying to do...
//setBooleanField(result, "mBoolean", false);
//Log.d(TAG, "mBoolean: " + String.valueOf(getBooleanField(result, "mBoolean")));
//param.setResult(result);
}
}
);
One thing that I should mention is that the real code I'm trying to change is obfuscated with Proguard. But I decoded it and looked for the method name - which was just "f" and use that instead of "getBar". I know I got the method name right because the error outputs the package name and class name correctly for the result object which is not obfuscated. And I'm sure this object has many public fields, but I can't access (or change for that matter) any of them without an exception being thrown.
What am I missing?
Whenever I've used this method, the first parameter has been the instance of the class (param.thisObject). I'm curious to know if it's possible to make it work the way you're trying to do with param.getResult().
But if you hook the constructor of the Bar class and try getObjectField with (param.thisObject, mBoolean) it should work.
PunchUp said:
Whenever I've used this method, the first parameter has been the instance of the class (param.thisObject). I'm curious to know if it's possible to make it work the way you're trying to do with param.getResult().
But if you hook the constructor of the Bar class and try getObjectField with (param.thisObject, mBoolean) it should work.
Click to expand...
Click to collapse
Maybe, but I'm not sure that allows me to achieve my end goal...
To be more specific, I'm trying to change the result of this:
https://github.com/android/platform...rc/com/android/email/SecurityPolicy.java#L120
Tried something simpler:
Code:
findAndHookMethod(
"com.android.emailcommon.provider.Policy",
lpparam.classLoader,
"a",
"android.database.Cursor",
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Log.d(TAG, "mPasswordMode = " +
String.valueOf(XposedHelpers.getIntField(param.thisObject, "mPasswordMode")));
}
}
);
Got this:
Code:
06-28 21:45:11.133 7201-7824/? E/Xposed: java.lang.NoSuchFieldError: com.android.emailcommon.provider.Policy#mPasswordMode
I don't understand what I'm missing...
I feel like an idiot...
I've been focusing on the methods and the fact that they are obfuscated that I forgot that the instance variables also are obfuscated.
It makes perfect sense now why none of this was working... Back to the drawing board.
Great Your question made me learn something new
PunchUp said:
Great Your question made me learn something new
Click to expand...
Click to collapse
Cool But what was that?
Save​

Casting and reflection issues in a method argument. okhttp3.OkHttpClient$Builder;->addInterceptor(···)

Hi guys, I'm trying to hook the constructor of
Java:
okhttp3.OkHttpClient$Builder
in order to add an interceptor that converts any OkHttp call into a curl call and log it (see https://github.com/mrmike/Ok2Curl by MrMike). But I'm having problems with reflection, say I must haven't understood it pretty well...
The idea is to call
Java:
.addInterceptor(okhttp3.Interceptor)
method JUST after the
Java:
OkHttpClient$Builder
instance has been constructed, but it's more painful than expected. (See code and code comments for further details)
Java:
@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
Class builderClass = XposedHelpers.findClassIfExists("okhttp3.OkHttpClient$Builder", lpparam.classLoader);
if(builderClass != null){
XposedBridge.hookAllConstructors(builderClass, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
CurlInterceptor interceptor = new CurlInterceptor(new Loggable() {
@Override
public void log(String message) {
Log.v("Ok2Curl", message);
}
});
/*
Attempt nº1:
Cannot do it this way, it throws an exception because there's not (and there's actually not) a method
'okhttp3.OkHttpClient$Builder#addInterceptor(CurlInterceptor)' since CurlInterceptor is from the Ok2Curl library.
Maybe the '.callMethod()' cannot make implicit casting?
*/
Object attempt1 = XposedHelpers.callMethod(param.thisObject, "addInterceptor", interceptor);
/*
Attempt nº2:
Declaring explicitly the argument classes that addInterceptor(···) has, does not help.
I get an exception: it could not find an ".addInterceptor(java.lang.Class, ...CurlInterceptor)" method, so
this means Interceptor.class was taken as one of the method arguments and not as an argument type.
Anyways, given the results from attempt 1, it seems that .callMethod() will not do implicit casting whatsoever...
*/
Object attempt2 = XposedHelpers.callMethod(param.thisObject, "addInterceptor", Interceptor.class, interceptor);
/*
Attempt nº3:
Explicit casting from CurlInterceptor to okhttp3.Interceptor did not help...
java.lang.NoSuchMethodError: okhttp3.OkHttpClient$Builder#addInterceptor(com.moczul.ok2curl.CurlInterceptor)#bestmatch
*/
Object attempt3 = XposedHelpers.callMethod(param.thisObject, "addInterceptor", (okhttp3.Interceptor) interceptor);
}
});
}
}
Thanks in advance!

Categories

Resources