|
It is remote, i don't think so.
|
|
|
|
|
So I assume that the way I am currently doing it is the only way? Any other ideas?
Thanks
|
|
|
|
|
You are right, the only way is to check with a timer because it is remote. Since remote server doesn't let you know when anything changes, it is not possible. Your app should check.
|
|
|
|
|
Hi
In my program I call a win32 API function which returns a function pointer as its result. How can I store and 'call' this pointer in C#?
The API function in question is LRESULT SendMessage(...) , which I map as IntPtr SendMessage(...) . The function whose pointer is returned by SendMessage has the form
int fn(void*, int);
so I created a delegate
delegate int RemoteFunction(IntPtr a, int b)
and I try to convert the IntPtr (originally LRESULT ) returned by SendMessage to an 'instance' of this delegate, like
RemoteFunction x = (RemoteFunction) SendMessage(...); // compiler error
So far I wasn't able to come up with a code that would at least compile, not to mention work.
Do you have any suggestions?
Any help appreciated, H.
|
|
|
|
|
maybe this helps:
using System;
using System.Runtime.InteropServices;
namespace com_example
{
class Program
{
[DllImport("user32.dll")]
private static extern int MessageBox(IntPtr hWnd, String
text, String caption, uint type);
static void Main(string[] args)
{
MessageBox(
new IntPtr(0), "Hello, world!", "My box", 0);
}
}
}
|
|
|
|
|
Thanks for you effort but this actually explains how to call an API function whose exact name I know at the design time. My question was rather how to call an external function that is returned dynamically (at runtime) in form of a function pointer.
The post bellow explains this perfectly.
Thanks anyway, H.
|
|
|
|
|
Not tried it myself, but you could look into:
System.Runtime.InteropServices.Marshal.GetDelegateForFunctionPointer.
Supposedly converts an unmanaged fp into a delegate.
10110011001111101010101000001000001101001010001010100000100000101000001000111100010110001011001011
|
|
|
|
|
Cool, I am sure this is it. Thank you very much!
H.
|
|
|
|
|
Is it possible to use C# to 'facelift' an existing MFC project's user interface part, but behind the new interface still running the existing MFC code?
For example, when a button clicked in the new C# interface, inside the event handler, it runs the existing MFC code.
Thanks in advance!
|
|
|
|
|
Katherine Williams wrote: Is it possible to use C# to 'facelift' an existing MFC project's user interface part,
Yes!
Katherine Williams wrote: but behind the new interface still running the existing MFC code?
Possibly?
Katherine Williams wrote: For example, when a button clicked in the new C# interface, inside the event handler, it runs the existing MFC code.
Almost sure you can't.
In C# and VB.NET the technique called P/Invoke (A.K.A PInvoke) allows calling functions from .dlls, making API calls for example. So I would suggest you have a look at the documentation for P/Invoke on MSDN to see if it will work in your case.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
It depends on how well separated the logic is from the UI code. If you can separate the C++ logic from the MFC code, you can use P/Invoke or write a C++/CLI wrapper over the existing code, and then call it from C#.
|
|
|
|
|
Hi guys,
we are back. I have a small problem with xml serialization.
Problem:
I can serialize an object as the type is know from the object passed in to be serialized, but after this is passed through a webservice, deserialization is a problem, as the type of the object is not known. The objects which are being serialized are all custom objects.
Scenario:
I have a generic serializer class. The code found below:
public String serializeObject(Object pObject)
{
try
{
String XmlizedString = null;
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xs = new XmlSerializer(pObject.GetType());
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
xs.Serialize(xmlTextWriter, pObject);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
return XmlizedString;
}
catch (Exception e)
{
System.Console.WriteLine(e);
return null;
}
}
public Object deserializeObject(String pXmlizedString)
{
XmlSerializer xs = new XmlSerializer(typeof(Object));
MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
XmlTextReader xmlTextReader = new XmlTextReader(memoryStream);
return xs.Deserialize(xmlTextReader);
}
When I am serializing the object, this works fine, as I can create a serializer with the object type from the object:
XmlSerializer xs = new XmlSerializer(pObject.GetType());
But when I come to deserialize the object from a string, I see two options which both dont work.
Either:
XmlSerializer xs = new XmlSerializer(typeof(Object));
Which gives me a "<custom class=""> not expected error" as the serializer obviously doesnt know about my custom class.
Or:
object newObject = Activator.CreateInstance(Type.GetType(strType));
Type type = Type.GetType(strType);
XmlSerializer xs2 = new XmlSerializer(typeof(Object));
Which again does not work as the serializer does not know of MyPackage.MyCustomClass
any thoughts on this will be highly appreciated.
Thanks
|
|
|
|
|
Hi,
Can any one help with links or articles that would guide me in creating a blog site using asp.net 2.0/ C# from the scratch?
Regards,
M.
|
|
|
|
|
http://lmgtfy.com/?q=c%23+blog+project
|
|
|
|
|
|
Hi,
You can try BlogEngine.NET which is totally free and amazing blog application. Source code is also opened and free. Have a look at it:
http://www.codeplex.com/blogengine[^]
Either you love IT or leave IT...
|
|
|
|
|
Hello,
I have a client / server architecture set up for remoting. The server is supposed to collect data on start up and broadcast to a database as well as any attached clients. My issues is that when the server starts up, the object isn't constructed until the first client begins to connect. Is there a way to configure the server side to "auto-start"? I need to collect and store the data regardless of any connected clients. Thanks!!
|
|
|
|
|
If anyone was interested in the answer....
I found that by its default behavior, server objects are ONLY activated/constructed from a client request. To solve my issue, once my server is started I automatically create a client object, attach to the server and detach. This forces the server object to construct. This website was very helpful: http://asp.dotnetheaven.com/howto/doc/remoting/nutshell.aspx[^]
|
|
|
|
|
Hellow Code Project
i have a problam whise my project mp3 player i will be glad if some one can
send me his e-mail that i can send him my project and help me whise my problom
tnx sagiklan
e-mail:sagiklan@gmail.com
|
|
|
|
|
That's not how CodeProject works. Everything is posted publicly for the benifit of all.
Post the specific part of the code that is causing you difficulty, explain what you expect or would like it to do, also post any errors or exceptions that occur and let us know what you've tried already.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
alaa.alatrash@gmail.com
Ala'a Al Atrash
|
|
|
|
|
I have a strange problem with unboxing.
Take this code:
public class MyCar
{
public string Name;
public MyCar(string name) { this.Name = name; }
public MyCar(int carNbr) { if (carNbr==1) this.Name="Honda"; else this.Name="Unknown"; }
public static explicit operator MyCar(string value)
{
return new MyCar(value);
}
public static explicit operator MyCar(int value)
{
return new MyCar(value);
}
}
private static MyCar GetMyCar(object car)
{
return (MyCar)car;
}
static void Main(string[] args)
{
string carName = "Honda";
object carObj = carName;
MyCar theCar = (MyCar)carObj;
MyCar theCar2 = (MyCar)carName;
MyCar theCar3 = (MyCar)(string)carObj;
MyCar theCar4 = GetMyCar((object)1);
MyCar theCar5 = GetMyCar(carObj);
MyCar theCar6 = GetMyCar(carName);
}
So can I get the function GetMyCar to return properly if the car type
is a string or integer? I though of doing something with Type, but couldn't find anything.
Anyone have any ideas?
Thanks in advance for your help.
|
|
|
|
|
simple...
your custom operators are only design to take a string or int, so you can only cast with those values. object is of type 'object'.
you could create an operator for 'object'...
public static explicit operator MyCar(object o)
{
if(o is string)
return new MyCar((string)o);
if(0 is int)
return new MyCar((int)o);
}
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
The first thing I thought of too but I get
user-defined conversions to or from a base class are not allowed
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
that's strange as im sure i have used the same functionality before, hold on....
oh no, that was different (not casting).
perhaps then a static function would be the way forward. surely that would work
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|