|
Interesting. I'll take a look.
Thanks.
|
|
|
|
|
I am working on a project the involves transferring data from a bar code scanner. The scanner runs PC-DOS and has a command line transfer utility that uses Xmodem. I have written an application that shells out and uses the same CLI utility to receive the file. This works, but I would like to impliment my own Xmodem protocol into my application to have more control over what is happening (and just to learn).
So far I haven't found any *free* examples of an Xmodem implimentation using C#. I have found several products that I can purchase, but this isn't what I had in mind.
I have found the specification for the Xmodem protocol and it's reads as being fairly straight forward. I'm curious to if anyone else has written the own implimentation, or if I'm overlooking why this shouldn't be too difficult.
|
|
|
|
|
therealmccoy wrote:
So far I haven't found any *free* examples of an Xmodem implimentation using C#. I have found several products that I can purchase, but this isn't what I had in mind.
If you can't find anything free using google or some other web search and you can't find anything by clicking "Search comments" in this forum (since it isn't indexed by google and the other major search engines...yet), then anything free doesn't exist.
You'll either have to implement your own xmodem APIs or purchase one of the libraries you've found. I'm sure the developers have spent a lot of time and planning and deserve what they get. You would like to get paid for your projects, wouldn't you?
Besides, with a paid product you can expect support. With free ones you're at the author's whim.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
You'll either have to implement your own xmodem APIs or purchase one of the libraries you've found. I'm sure the developers have spent a lot of time and planning and deserve what they get. You would like to get paid for your projects, wouldn't you?
In order to get paid for any of my projects I will need to learn a lot more. With that in mind I guess I will be implimenting my own interface (ohhh.. what a challenge). During the course of this project I'm sure I'll have more questions, but when I'm done this API it will be released into the public domain, much like the original Xmodem specification was.
For others searching this forum and looking for information on an Xmodem implimentation (as well as the total lack of any type of serial support in .NET) check the following site:
http://ourworld.compuserve.com/homepages/richard_grier/xmcomm.htm[^]
|
|
|
|
|
There should be in .NET 2.0, codename "Whidbey". See http://msdn2.microsoft.com/library/System.IO.Ports[^] for details.
Because "Whidbey" is currently in beta, there is no gaurantee that what you read now will be there in the release, but do have comfort in the knowledge that serial support in the BCL is something that has been requested by the community for a long time.
If you need to or want to implement your Xmodem implementation for .NET 1.0 and 1.1, I recommend downloading[^] the .NET Framework 2.0 runtime and SDK and using ildasm.exe - the IL Disassembler - from the SDK's Bin directory to examine how the System.IO.Ports namespace classes work with the Win32 APIs. You can also use .NET Reflector[^] to decompile (and disassembler) the assemblies to get tips for your own implementation.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I am trying to return a string(char*) from a c++ dll and the string i return comes out blank. can anyone help me on this.
Vinayak D. Labade
|
|
|
|
|
Maybe, but since you didn't provide any required information - like the C# method and C++ function signatures - it's impossible to help you.
One thing I can tell you, however, is that keep in mind a string (System.String ) is already a reference type, so unless you see char** don't use ref or out with the parameter, despite any [in] or [out] comments you may see in the API documentation.
If you paste your C++ signature, I can tell you what the C# signature should be. Be explicit.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thnaks ...
here is the code snippet taht I am using.
C# code
-------------------------------------------------
public class newtestdll
{
[DllImport("C:\\DLLDEV\\qw\\debug\\qw.DLL", EntryPoint="ReportVersion", SetLastError=true,
CharSet=CharSet.Unicode, ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern string ReportVersion(string str);
}
-------------------------------------------------
str = newtestdll.ReportVersion(string);//function call
--------------------------------------------------
**************************************************
--------------------------------------------------
C++ definition
---------------------------------------------------
__declspec(dllexport) char* CQwApp::ReportVersion(char* a)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
a = "return String";
return a;
}
---------------------------------------------------
I even tried using StringBuilder but am not able to modify the StringBuilder properly.
Vinayak D. Labade
|
|
|
|
|
I see many problems with that.
First, never hard-code the path to your DLL from which you want to import a function. Just set the DLL name and make sure the directory is in your PATH environment variable or in the local directory of your application that runs this code (not necessarily where the DLL assembly that may contain this code is). This is how Windows (and actually other OS's like linux and UNIX) finds DLLs. Read the documentation for the native CreateProcess API for more information.
Seconds, you're setting CharSet to CharSet.Unicode . char* is an ANSI string. Be sure to read the documentation for the CharSet enumeration for details.
Third, you don't need much of the fields you're setting in the DllImportAttribute . You only need exact spelling if, for example, you're importing SomeFunctionA or SomeFunctionW , where you don't want an "A" or "W" appended depending on the CharSet . It won't hurt, though. And only set SetLastError to true if your function actually sets the last error. I see nothing in your code that would.
The simple signature for your native function follows:
[DllImport("qw.dll")]
static extern string ReportVersion(string a); However, there are a few reasons why this won't work and a few things you should be aware of.
A char* is, obviously, a pointer to a char . If you're setting this to another string the pointer is is modified to point to another string such that when your function returns what you passed as the parameter is the new string. You don't need to return it as well. Besides, you should never return a string because it's not possible to return an error code if the function fails. You're only choice is to return NULL, which doesn't tell you what actually failed. You could use SetLastError in your native code, but it's far better to return an error value.
Also, you're importing a method - not a function. Methods use the CallingConvention.ThisCall - at least instance methods. Now you have a problem.
You can't call your instance method without a context to whatever this would be in your native code (an instance of CQwApp )
This means you have to set the DllImportAttibute.CallingConvention field to CallingConvention.ThisCall and create a pair of proxy functions (not methods) to create and destroy (or just a single proxy method to get) an instance of CQwApp . See a previous reply regarding this issue at http://www.codeproject.com/script/comments/forums.asp?msg=771919&forumid=1649#xx771919xx[^].
Finally, you should consider that - if your method really is so basic and doesn't require instance data - either define it as static and use the __cdecl calling convention (which means you don't declare any DllImportAttribute.CallingConvention , though you may need to set the EntryPoint explicitly since the name will be C++ mangled) or declare it as a function instead of any sort of method. That will make it easier to P/Invoke.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for the reply. I was able to call the function and return a string as required. The dll function i am calling has some output which i need.
i am facing another problem though.
I get error for this code in the dll
---------------------------------------------
FILE *stream;
GetCurrentDirectory( 256, buffer );
strcat( buffer, "\somefile.txt" );
stream = fopen( buffer, "r" );
fseek( stream, 0L, SEEK_SET );
fscanf( stream, "%d\n", &ct_ );
----------------------------------------------
what do you think might be the issue here
if i call the same code from a MFC exe it works fine but not when i call from C# code
Thnaks & Regards,
Vinayak D. Labade
|
|
|
|
|
What's the error? I can't really help you if you don't tell me what's wrong.
I can guess, however, that you can't open the somefile.txt from the current directory and you're only opening it for read access, and it won't be created.
The CLR works differently than a typical Win32 EXE (MFC is just a wrapper for Win32 APIs) and what you expect to be the current directory may not be.
Also keep in mind that even with native applications, the current working directory (retrieved by GetCurrentDirectory ) is not necessary the directory in which the application is running. If from a console window you execute an application from another directory, the directory which was the current directory is used. For applications launched through shortcuts, if any working directory is specified for the shortcut that is used. There's other cases that will cause the current working directory to be different than the application directory.
To get the application directory, call GetModuleFileName(NULL, szBuffer, MAX_PATH) , where szBuffer is a TCHAR szBuffer[MAX_PATH] .
Finally, regarding your native code there's a lot of things you should consider changing. Don't use "magic numbers" like 256. What's that mean? Use constants that are more descriptive like MAX_PATH (which is actually 260, and is what Windows defines as the maximum characters in a path). Also don't use unsafe string manipulation functions like strcat that don't ensure NULL termination (which is one major cause of buffer overruns, the most common cause of security vulnerabilies and other types of bugs). MSDN recommends using StrSafe[^], which are safe implementations of string manipulation functions.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am looking to implement a web site that can conform to the strict standards of US govt secure internet web site protocols for password and username use. Things like expiring passwords, keeping track of whether a password has been used before, or a password closely used before. Password complexity and secure storage of passwords and on and on. Basically I am looking to see if there has been a COTS product that has been developed to perform all your password needs for a secure web site or will I have to code all this my self? Any help or direction is much appreciated. Thanks.
Big Friendly Letters : DON'T PANIC
|
|
|
|
|
I have some documents stored on a server, I want to use these as a template and populate them with some infromation from a database.
At first I thought of automating Word, this worked nicely on my local machine when I tried it out as a normal winform. But then when I tried it on the webpage I got a "The message filter indicated that the application is busy" when I tried using it. I've looked around alot and found no solution for this, so I'm more or less ready to drop all the work I've done so far regarding this.(Iterated through bookmarks and replaced the text)
Now I've been thinking that Word 2003 is saved as XML, so perhaps I could replace text in that instead. In the Word file I have certain keywords I want to replace, for example User = @usr then I would like to replace @usr with something from the database.
Problem I have is that XML is a very big subject and I have problem figuring out if this is possible or not. I dont want to spend more days(wasted alot of days on learning how to automate word)if it is not possible(In a easy way).
So, anyone have any tips how I can do or tips on what I should read up on.
Or is it possible to use any other way of searching the text and replacing instances like that in a easier way?(We are talking about Word 2003 documents only, or if it is easy 2000 documents too)
|
|
|
|
|
Hello,
I'm new to this site, as an active member, and i've been reading it for a while now to.
But today for the first time i couldn't find an answer to my problem, even google couldn't help me out.
So what is the problem?
I bought this fancy new laptop (acer travelmate 8008) and I'm playing with it, but I realy don't like the "on screen" displays the basic software gives mee. So I want to write it myselve using C#.
Now the first problem is, the special keys I'm talking about don't have a ascii code or are ingnored by the keydown, keypress and keyup functions.
So how do i detect these events?
I tried searching for an API call but couldn't find one, or i didn't understand what the writer talked about. (new to API call's)
Maby i could use a DLL of the program that handles the "special keys"?
anny help will be greatly apriciated...
and thanx in advance
ps: hope this is the right forum
pss: maby an idea for an article?
|
|
|
|
|
The OEM keys (original equipment manufacturer) are supported through the KeyEventArgs.KeyData property when you override OnKeyDown (best when extending classes in which the keys are handled) or handle the KeyDown event. See the property documentation in the .NET Framework SDK for more details.
Compile the following example:
using System;
using System.Drawing;
using System.Windows.Forms;
class Test : Form
{
static void Main()
{
Application.Run(new Test());
}
TextBox tb;
Test()
{
tb = new TextBox();
Controls.Add(tb);
tb.Multiline = true;
tb.Dock = DockStyle.Fill;
Text = "Press any key";
KeyPreview = true;
}
protected override void OnKeyDown(KeyEventArgs e)
{
AddLine(e.KeyData);
base.OnKeyDown(e);
}
void AddLine(Keys keys)
{
tb.AppendText(keys.ToString() + Environment.NewLine);
}
} With keys there really isn't much reason to require P/Invoke, though P/Invoking the native GetKeyState or GetAsyncKeyState APIs can be helpful for toggle keys that wouldn't be in KeyEventArgs.Modifiers .
For more information on P/Invoke (Platform Invoke), read Consuming Unmanaged DLL Functions[^] and Marshaling Data with Platform Invoke[^] in the .NET Framework SDK.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
this is truly great info and solves most of my key problems.
Only a few keys (like the powermanagement key and programmable keys return LButton, OemClear (value 255).
These buttons are not supported by the .NET framework (i think).
So I'll have to find a workaround for these.
And special thanx to you Heath Stewart for your quil and helpfull reply!
|
|
|
|
|
Actually, they would be supported but you need to take that data into consideration with other properties of KeyEventArgs . You're only limited to 256 bits for keys, but there's modifiers. I recommend reading the documentation for the GetKeyState API at http://msdn.microsoft.com/library[^] to learn about keyboard buffers and keys.
Your OEM's special keys are still keys and/or modifier keys. All you need to do is figure out what their values are and in what properties the .NET BCL puts them into the KeyEventArgs class. Worse case scenario is that you have to P/Invoke GetKeyState or GetAsyncKeyState , but that's fairly simple if you read those P/Invoke topics I linked earlier. You should also check out http://pinvoke.net[^] for common API signatures in managed code.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I'm working on an app that, among other things, stops the print spooler and clear the print queue. The "ManagementObject.InvokeMethod("StopService", null)" call works with most services, but not the print spooler. When I go into the Management Console and stop the Print Spooler manually a dialog comes up and tells me "When Print Spooler stops, these other services will also stop" (TCP/IP Print Server). I assume that my method call is running into this same thing and doesn't know what to do, so it doesn't stop the service.
I know there is a way for me to pass arguments into that method call, but I'm not exactly sure how to pass the command through to say "yes" if it encounters a situation like I mentioned above. Anyone know how to do this?
Thanks,
Seth
|
|
|
|
|
The service control manager (SCM) handles querying for dependent services and stopping them. What you see in the user interface is different than what happens. When you stop a service the SERVICE_CONTROL_STOP message is sent to the service's Handler or HandlerEx control handlers (this is true with the ServiceBase class, which encapsulates the native functionality). So, you're right, the code when the service is stopped is the same.
But the code that stops a service is different. The Services snap-in for MMC queries the service for dependent services first, then - if you click "Yes" - stops each one, querying those for dependent services. Finally, the select service is stopped.
You would need to do the same in your code. See http://msdn.microsoft.com/library/en-us/wmisdk/wmi/wmi_tasks__services.asp[^] for examples of how to determine the dependent services (at the bottom). You'll find some other useful examples of queries to use with the ObjectQuery class.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Awesome. That's exactly what I needed. Now I need to decide whether my code should also start any dependent services when it starts a service or if I should leave that to the user...
Maybe I'll just notify them.
Thanks very much!
|
|
|
|
|
It's often better to not do too much automatically that isn't required. Services that depend on yours would have to be stopped, while they don't necessarily have to be started.
As a compromise between you and your users, I recommend prompting them - as you should when shutting down your service - to start services that depend on your service. When shutting down a service, you can do a simple Yes/No dialog (using MessageBox.Show with MessageBoxButtons.YesNo ). If they choose No you can't stop your service. Simple.
When starting it back up, however, it's more difficult than that. You could develop your own Form derivative with, perhaps, a CheckBox that states something like "Also start services that depend on this service". Have it unchecked by default.
The tricky thing is that they might've set such a service to Manual and don't want it started. You should check for that, too. In such an event, though, how do you know they don't want it started? To get around this - if possible - record which services you stop and only re-start those if the user has opted to start such services.
Or just don't start them like the Services snap-in does.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Right. I implemented a message box that informs them that other dependent services stopped (and the names of those services), just so they know. The people who will be using this will know what services they want running, and it's simple enough for them to restart dependent services themselves if they so desire. They can handle doing that thinking on their own.
Interestingly enough, I've found that (in at least some cases) when you start a service that depends on another service that is stopped, it will start that other service first. The TCP/IP Print Server will start the Print Spooler if it's stopped when you pass it the "StartService" method, for example.
|
|
|
|
|
I have an object (not control) that belonges to a Control. Basically, the object (element) is a helper class to divide the control into sections in order to simplify buildup and rendering. Very close to the Avalon UIElement idea (in fact, I named my object also UIElement after that).
<br />
public class UIElement : IDisposable<br />
{<br />
___public Control mainControl{...};<br />
___public void DrawElement(bool childElements){...};<br />
___public Location location{...}<br />
}
Imagine that you have a custom-made toolbar. The base of this toolbar is a Control (or UserControl if you will). Now the grip of the toolbar is one element, the toolbar item is second element and so on ... All sections of the toolbar (grip, items etc) are drawn by UIElements.
I am wondering how could I add mouse panning functionality to the element, so that I could have different sections of the control having different mouse events (like in the former example, when you click on the grip element you start dragging or when you click on the item element you open up a popup menu).
Any ideas how is the mouse handling done in the Control class ?
P.S. When ready, I'll release the code to public ...
|
|
|
|
|
desmond5 wrote:
The base of this toolbar is a Control (or UserControl if you will).
That would be incredibly inefficient with too much overhead. A UserControl is a container control, used for hosting other controls like a Form hosts controls. This should not be used for single objects.
Even more advanced toolbars that seem to host other controls like a combo box are not container controls. They typically "site" (position) those controls at a particular location and move them when the control itself is moved.
desmond5 wrote:
Any ideas how is the mouse handling done in the Control class ?
Much of the mouse interaction is not handled by the Control class at all. Almost every Windows Forms control in the BCL encapsulates the related Windows Common Control - the very same native controls you see throughout Windows and Windows applications. This gives a consistent user interface whether your application is writtin in C/C++ using the Win32 APIs, MFC (C++), VB, or .NET (or a slew of others, excluding Java that wrote it's controls from the ground up for consistency across platforms, which is arguably less important that a single platform where most users spend their days).
If you want to see the implementation for yourself, learn to read Intermediate Language (IL) and use the ildasm.exe (IL Disassembler) application that ships with the .NET Framework SDK and is located in the Bin directory of the .NET Framework SDK installation. This is installed by default with VS.NET under the VS.NET installation root.
You could also use a decompiler like the .NET Reflector[^].
For your approach where you're defining everything in managed code, a more common approach is to have each UIElement implement a Click handler like so:
public class UIElement : IDisposable
{
public abstract void OnClick(MouseEventArgs e);
} Override OnMouseDown , for example, on your toolbar control and pass the MouseEventArgs passed to you to the UIElement at those client coordinates (i.e., 0,0 corresponds to the upper-left corner of the control that was clicked - not the screen). That will allow you to get any relative mouse click point for the element as well as any modifier keys.
A better design would be to encapsulate only the properties of the MouseEventArgs you want, which makes this easily callable for key events (like pressing the [Space] key when the UIElement has the focus, if you implement focus within the toolbar itself).
Regarding your naming conventions you should really read Naming Guidelines[^] in the .NET Framework SDK. Methods (not functions, mind you) should never be lower case, nor should properties. Fields may be, as it really doesn't matter how you name private fields (no one should see them anyway, but take into account how they're serialized, implementing ISerializable for custom serialization if needs be).
It's important to follow the guidelines as it makes developing applications using your library easier when it's consistent with the other libraries a developer would be using. Just think of all the classes, members, etc. that you use from the BCL? Have you ever seen a method that begins with a lower-case letter? A property, or a class? Not in the BCL (base class library) you won't.
It's good to run your assemblies through FxCop[^], which will not only catch naming violations (not typically bad violations, but following the guidelines is helpful for your clients) but many other errors as well.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
There is a method of the DataTable object that I require to access from various methods of my class basically to retrieve the column name as a specific index.
I have created a private property in my class to access this method and defined it similar to as follows:
<br />
private string ColumnName<br />
{<br />
get {return DataTable.Columns[ColumnNumber].ColumnName.ToString();}<br />
set {DataTable.Columns[ColumnNumber].ColumnName = value;}<br />
}<br />
Is this acceptable practice?
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
LearnVisualStudio.Net
|
|
|
|
|