|
I'm probably missing something increadibly simple. Bascially, I've been playing with MySQl and want to output my queries in a console.
If I run a console app, that's no problems. But if I create a windows app, it doesn't work. Right now I have it set up so that you click a button a connection to the sql server is made. Then I sorta expected a console to pop up and display some query information. Then I close the connection.
The connections are working. I verified that. But Console.Writeline just doesn't display any output. Is this because I created a windows app and not a console app?
As a next step I'm thinking of creating a text box and displaying the query in there. But I just wanted to ask about my console problems.
|
|
|
|
|
Console class only works on console application... if you want just to test your application and show some message use a message box....
MessageBox.Show("Test Message");
Works as well...
cya
Wender Oliveira
.NET Programmer
|
|
|
|
|
|
If you want console output to be visible when used in a Windows Forms application, you have to build the executable as a console app (with /t:exe instead of /t:winexe to the csc.exe command-line compiler, for example). This will start a console window then start your Windows Forms application. Any time you use any of the Console methods, that initial console window is what is being referred to; otherwise, there is no console for the Windows Forms application. It's a completely different subsystem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Okay cool. Thanks everyone. I was thinking of using a text box actually and having stuff display in there. I was using MessageBox for some lines butn it didn't work for others.
I just assumed that if you called a console window in c# that a console window would pop up. even if calling from a window app. Oh well.
|
|
|
|
|
I'm having some trouble implementing drag & drop between two treeviews in two different winform applications.
It works just fine between two treeviews in the same application though.
What I do is this:
<br />
private void OnDragDrop(object sender, System.Windows.Forms.DragEventArgs e)<br />
{<br />
...<br />
if (e.Data.GetDataPresent(System.Type.GetType("MyNameSpace.MyTreeNode2")))<br />
{<br />
data = (MyTreeNode2)e.Data.GetData(System.Type.GetType("MyNameSpace.MyTreeNode2"));<br />
<br />
if (data != null)<br />
MyTreeNode2 newFolder = (MyTreeNode2)data.Clone();<br />
<br />
...<br />
}<br />
(The MyTreeNode2 class is inherited from the standard TreeNode class, adding only some extra properties)
This will work fine when doing it with strings, probably since the format for strings is well understood or
something while the format of my treenode object is not so easily shared between applications. Do I need to
implement some kind of serialization stuff for my object for this to work, and pass the string? I know that there
are a couple of predefined data formats available, but in java with WFC (which is where I've just this method
before and it worked better I used the object type DataFormats.CF_WFCOBJECT and it worked fine. Is there a corresponding
solution implemented in .NET/C#?
(It works for a single child node in my treeview, but not for a folder with child elements...)
Can anybody help me?
|
|
|
|
|
Yes, you'll need to marshal the data for transport across application boundaries. The Marshal class may be of some help. Perhaps define a struct or something easy to marshal, fill that with information from the TreeNode , marshal it as an IntPtr or something (declaring it in global memory, for example), and then pack that in the DataObject . That would probably be the easiest solution.
The way you're doing it now would work within the instance of the application.
Also, the format must be the same. So unless these two applications are sharing the assembly that defines your MyNameSpace.MyTreeNode2 class, then you need to just specify a string (maybe something like "MyNameSpace.MyTreeNode2" instead of Type.GetType("MyNameSpace.MyTreeNode2") , which - defined in different assemblies - would yield a different type string).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Isn't it possible to serialize the raw object data from memory into a binary data format and just transport that?
If I just define the MyTreeNode2 class as serializable with the [Serializable] attribute before the class definition
and then I should be able to Serialize it into a byte array or something right? And that should be no problem to
marshal I reckon...
From what I could conclude there is built-in support for this type of binary serialization and deserialization,
(BinaryFormatter class) which should mean that I should be able to use this method without a problem to transport an object..
So, if my thinking is right, can you tell me what's wrong with this? All I know is it doesn't do what I want it to...
(code handling start drag event)
<br />
IFormatter formatter = new BinaryFormatter();<br />
<br />
MemoryStream ms = new MemoryStream();<br />
<br />
formatter.Serialize(ms, draggedItem);<br />
<br />
DataObject dObj = new DataObject( "MyNamespace.MyTreeNode2", ms.GetBuffer() );<br />
selectedTreeView.DoDragDrop( dObj, DragDropEffects.All );<br />
and here is what I want to use on the receiving side. But it doesn't work, the method actually returns after the last line (data = ...) without even continuing execution of the remaining part of the method, or at least the debug stepper of VS won't continue past this point. (Why does this happen?)
(code for handling drop event)
<br />
if ( e.Data.GetDataPresent("MyNamespace.MyTreeNode2") )<br />
{<br />
MyTreeNode2 data = null;<br />
IFormatter formatter = new BinaryFormatter();<br />
<br />
byte[] serializedBytes = (byte[])e.Data.GetData("MyNamespace.MyTreeNode2", false);<br />
MemoryStream ms = new MemoryStream( serializedBytes );<br />
data = (MyTreeNode2)formatter.Deserialize( ms );<br />
...<br />
|
|
|
|
|
An exception might be thrown that would cause execution to stop.
What I described is a way of "serializing" it. You're persisting the object in global memory. Here you might have a problem depending on how .NET's DataObject handles a buffer. You still can't simply cross application boundaries with reference data (of which an array is). It needs to be either packed into memory (like strings and primitives) or locked in global memory (with COM, there's other ways where you can persist data to storage or stream it, but .NET doesn't expose that which is why I've been working on a library that - among other things - contains such an implementation).
Also keep in mind that simply serializing your TreeNode derivative might not be appropriate. Remember that there are other public properties that the BinaryFormatter will traverse and serialize, like the Parent property (so you're actually serializing almost an entire tree because of the references). You should implement ISerializable and serialize only what you need (Text , Tag , etc.). Don't forget about the constructor with the serialization signature.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
You should be able to do it by looking at the raw data bytes. This is more complicated than GetPixel(), but the System.Color structure definitely only supports 8bpp. The upside is that this method can be a lot faster than calling GetPixel thousands of times.
To get at the raw data for a System.Drawing.Bitmap you first have to lock the bits (so the array doesn't move around in memory while you're doing unsafe pointer stuff), then you can get a pointer to the start of a particular scan line, which will be a pointer to the raw array of bytes for that scanline. All of this requires the "unsafe" keyword, which requires a special compiler flag.
Inside the unsafe { ... } block, first call LockBits() on the Bitmap to get a BitmapData structure. Then you can use the Scan0 property of the BitmapData to get a pointer to the first scanline. In your case you would cast this to a (ushort*) type, since each 16bit value is a ushort. Incrementing the pointer will point to subsequent ushort's on the same scanline.
To get to the next row (scan line) of the image, add the value of the Stride property of the BitmapData to the Scan0 value to get the pointer to the start of the second scan line.
I don't have a 48bpp image to try this on, but here's some code for a 32bpp image which you can use as a starting point:
using (Bitmap bmp = new Bitmap("image.tif"))
{
int[,] raw = new int[bmp.Width, bmp.Height];
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
unsafe
{
BitmapData data = bmp.LockBits(rect,
ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
int max = int.MinValue;
byte *p = (byte *) data.Scan0;
for (int y = 0; y < bmp.Height; y++)
{
byte *q = p;
for (int x = 0; x < bmp.Width; x++)
{
byte red = *(q++);
byte grn = *(q++);
byte blu = *(q++);
raw[x, y] = blu + 256 * grn + 65536 * red;
}
p += data.Stride;
}
bmp.UnlockBits(data);
}
} In your case you'll want ushort instead of byte everywhere, and you wouldn't be saving the pixels as 32-bit ints of course, but the logic is the same. It's also possible that I have the red/blu values backwards here, but you can figure that out.
|
|
|
|
|
When I process this event, it gets called multiple times per page. Why is this? How can I stop it, or should I use another event?
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
Are you trying to detect when the page has loaded? try the body.onload event, but be aware that this will only fire when all of the content has downloaded (images etc.). You could also put a call to your function in tags at the bottom of the page if you want it to fire when the html is downloaded.
Find my .Net blog at <a href="http://hiltong.blogspot.com">http://hiltong.blogspot.com</a>
|
|
|
|
|
body.onload is not exposed via the mshtml interface. I have an AxWebBrowser component inside my Windows Forms project. That's where the event is hooked.
Sammy
"A good friend, is like a good book: the inside is better than the cover..."
|
|
|
|
|
It fires because the page your loading supports frames. The event will fire when the frame page is done loading (usually the one your navigated to), and it also fires for each subpage that the frame page loads.
This behavior is by design. You can't turn it off.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have a third party source code in C which i have converted into a win32 dll.
namely have introduced a new entry point to replace main
__declspec(dllexport) int maindllentrypoint(int argc, char* argv[])
Now i try to invoke it from a c# console application
[DllImport
("D:\\.............\\xxxx.dll")]
public static extern int maindllentrypoint(int argc,string[] argv);
class ClsInvokeThirdParty
{
[STAThread]
static void Main(string[] args)
{
string[] prm=new String[]{="xxxx.exe -c d:\\..\\tihrdparty.conf -l d:\\dlllogs.txt"};
ClsInvokeThirdParty.maindllentrypoint(1,prm);
Console.WriteLine ("Press enter to abort ");
Console.ReadLine();
}
}
I get a NullRefernceException-Object reference not set to an instance of an object..
When I debug into the third part code ,I find that the program aborts atthe first pace that argv[0] is being referenced within the dll.
What should I do?
|
|
|
|
|
First, never hard-code the path of the DLL. This will most likely be in a different location on different machines. Just specify the DLL name and make sure that it's location is specified in the PATH environment variable (or add it to a directory that's already in the PATH).
Also, it seems that all you're trying to do is invoke an executable, so why not just use Process.Start , which allows you (through various means) to invoke an executable and pass it command-line parameters.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The executable needs to be built into a dll,to map into our process space.
This is needed owing to certain organizational practices.
But I need help in sending a pointer to character array from managed code -something which the main function(and hence the correponding dll entry point clone that i set up) expects .
Any help would be much appreciated.
|
|
|
|
|
You map a DLL in your process space just to execute an application (out-of-process)? Odd, but whatever.
See the MarshalAsAttirbute class in the .NET Framework SDK. Since you're using char* and not TCHAR* , be sure to specify CharSet=CharSet.Ansi in your MarshalAsAttribute and to use the right UnmanagedType enumerations to declare it like so:
[DllImport("xxx.dll", ExactSpelling=true, CharSet=CharSet.Ansi)]
private static extern int main(
int argc,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex=0,
ArraySubType=UnmanagedType.LPStr)] string[] argv); But what's the point of sending an array (marshalling it is slower) if you're just going to pass a single string? All you're doing is wrapping CreateProcess or something (which is a waste since Process.Start encapsulates that already) so why not just declare a function that takes a string argument?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
to stop it returning 1/1/1 if the user does not enter a date into the textbox then i want my database table to show no date entered?
|
|
|
|
|
You cant assign null to a value type in .net. You can only assign null to references.
Best way to handle this would be to compare with DateTime.MinValue.
It's yet another shock to our system to discover that not only are we not the centre of the Universe and we're not made of anything, but we started out as some kind of slime and got to where we are via being a monkey. It just doesn't read well.
Douglas Adams
|
|
|
|
|
many thanks that worked a treat passed DateTime.DbNull.Value
|
|
|
|
|
HI~
Is there any function in eVC++ which can pass some parameters to a running C# program?
"CreateProcess" can pass some parameters as a argument when a process start. However, how about the process is running?
Thanks~
|
|
|
|
|
There's many ways. You could expose your .NET components as CCWs (COM-Callable Wrappers) and communicate with them that way (most likely using the Running Object Table - or ROT - to get the running instance, but any singleton pattern will do).Read my article Embedding .NET Controls in Java[^] for an example (ignore the Java stuff; pay attention to how the C++ bridge marshals calls on the .NET Control exposed as a CCW). Also read Nick's article, Creating a CCW for COM-Enabled, non-.NET Applications[^].
You could use DDE, though adding support for this archaic API to .NET is cumbersome (but I do believe I've seen an article here on CP that may help).
You could use any IPC (inter-process communication) mechanism, such as - but not limited to - .NET Remoting (easy to implement on the .NET side, but forces you to parse and create XML fragments and post them to a TCP channel, for example, yourself in eVC++, interop'd IPC functions from the Win32 API (at least whatever is supported by eVC++ for the Windows Mobile architecture), etc.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi , anyone know if it is possible to somehow match a regex pattern at an exact index?
eg:
string text="abc 0xffaabb def ghijkl";
regex r=new regext ("0x[0-9a-f]+");
match m=r.match (text,4); //<-- i want to match at position 4 ONLY , not 5,6,7,8 or anything else , only on index 4
[edit]
ofcourse i can check if the match object returned is located at the same index, but that would lead to seriously bad performance since the whole string will be scanned. i need it to check on the index only..
[/edit]
the length param is apparently not for this , it only limits how long the result can be , and i dont know that in advance , it can be any length
//Roger
|
|
|
|
|