|
|
Hello
Well, you can do almost the same with C# using SerialPort class, but for lpt, USB, and other ports or devices you have to do it this way:
1- Call API function CreateFile() with the port/device name.
2- Get the handle returned by that call and pass it to FileStream constructor
3- Use that FileStream object to read/write from/to the port/device.
I hope that was close enough.
Regards
|
|
|
|
|
Hi Nader, thanks for your response.
I guess the example I gave was a bit too specific. In general, I am looking for the general accepted way for threads and forms to send messages to each other asynchronously. For a more general example, Lets say there is a parent form that launches another form using "Show" so that the new form behaves like a modeless dialog. Now, the new form has controls of various stripes on it and the parent form need not know about everything that is going on on this form but needs to be notified of certain key events. And lets say that simply calling some member function of the parent form from the child form isn't quite going to work. In Win32 programming and MFC, we would send asynchronous messaged from one window to another using the messaging system built into windows. As long as your thread or window has a message pump, then it should get the message.
Is there anything like this for C#?
Regards,
Mark
|
|
|
|
|
Well, I think you are getting a little meticulous about details here . It's nice though not much seen these days.
Exchanging messages between forms has many forms , depending on your needs and design. There may not be a best practice that is considered an industrial standard or a windows logo criteria, rather it's just a mere advice that could be criticized by another programmer.
Jethro63 wrote: Now, the new form has controls of various stripes on it and the parent form need not know about everything that is going on on this form but needs to be notified of certain key events
Once I read that sentence I had the word interface jumping across my eyes. It would be a nice way to make a standard of communicaion between your parent form and different MDIChild types -ie. through a common interface-.
Jethro63 wrote: And lets say that simply calling some member function of the parent form from the child form isn't quite going to work
Well, actually it can be done using Parent.Invoke() method for events that you want your child form to wait for the parent to excute its code. If you want to fire an event in the parent form and not to wait until it's done, call Parent.BeginInvoke() instead. Both calls of course are from your child forms.
Jethro63 wrote: In Win32 programming and MFC, we would send asynchronous messaged from one window to another using the messaging system built into windows. As long as your thread or window has a message pump, then it should get the message.
Well, you still can use the same thing in C# if you like it. Actually the messaging system is still applicable -even in Windows Vista I think-, so simply:
1- In the child form call Windows API PostMessage() or SendMessage() functions -whichever suits you-, using P/Invoke and give it the handle of the parent form.
2- In the parent form implement IMessageFilter interface and use its PreFilterMessage() to catch your custom message or use any way that suits you -usually there are predefined handlers- to catch WM_ standard messages if you wish to send them.
Jethro63 wrote: Is there anything like this for C#?
In addition to the above there are more improvised ways like exchanging data between forms -considered as threads- using System.Runtime.Remoting.IPCChannel class, or even sockets -one form is listener and the other is client-, but I don't think they would be an interesting choice to you.
I hope that was useful.
Regards
|
|
|
|
|
Hi Nader:
Thanks for the advice. I am looking into Parent.BeginInvoke(), which I recognized in passing and will now take a closer look at.
Cheers,
Mark
|
|
|
|
|
Hello,
I have a problem with using the SmtpClient class in .net, It works fine when sending mails within the mail server (same domain). But as soon as i send to an external mail-address, i get the error: "Server Prohibited. We do not relay". Im not sure what to do here.
If you have any ide, please give me a tip.
Regards
Hmitosh
|
|
|
|
|
That's not a problem with the class, that is how your SMTP server is configured, as the message indicates.
led mike
|
|
|
|
|
Usually Most ISPs block using SMTP servers to send email other than their own SMTP Server. You should ask your ISP to get their SMTP Server, and if authentication required ...etc... information... After that, try with your ISP's SMTP server to send email. Hope that will work.
|
|
|
|
|
i want to assign multiple values to one key value eg.
a: 1,2,3,4
b:5,6,7,8
nd so on
what data structure shall i use as hash table is of no use in such situation
Bia
|
|
|
|
|
You can store your array of values in an ArrayList, and then store that in the Hashtable.
Ex:
Hashtable hashtable = new Hashtable ();
hashtable["a"] = new ArrayList (new Int32[] {1, 2, 3, 4});
hashtable["b"] = new ArrayList (new Int32[] {5, 6, 7, 8});
...
|
|
|
|
|
yeh we did that but how can we get the key by knowin the values is there any way??
cuz it alwaz givs us null
|
|
|
|
|
I suppose you'd have to iterate through each key and then use ArrayList.IndexOf() to see if your particular value was in that key's ArrayList.
|
|
|
|
|
yeh thanks i l try that
beu
|
|
|
|
|
Hi,
I have a web application wherein I need to call an outside DLL which executes a function call which is taking a lot of time. So what I need to do is that upon page_load of the application, I spwan a new thread which will call that function in the DLL and start initializing it.
Now, when the user actually goes to the page and requests another function from the same DLL, the 2nd thread which has been spun earlier would have almost done with initialization or getting it to completion. So this main thread should then wait for the 2nd thread to complete its initialization task at hand and when its done, it should take over from that and do normal web page and code processing further.
How do I do this? Which Threading methods do i use ?
Pls guide me as I am totally new to multi threading.
Thanks
Omkar
|
|
|
|
|
Hello
Revise WaitHandle class in your MSDN.
Regards
|
|
|
|
|
Hai,
I am Balu using ie5 browser using this browser popupwindow is opening fine but the same popup is not at all opening in the mozilla firefox browser is there any condition for browser compatability? can any body help for this situation.
regards,
Balu.A
|
|
|
|
|
Some browsers prevent popups depending on the security level of the browser Firefox is a good example. It's a settings issue.
Regards
|
|
|
|
|
Hi there,
Does anybody know a possibility to read the Video and Audiostream of a network and write it into an avi file in realtime using C# ? Audio and Video Streams must be multiplexed from different sources from the network.
It would be great if anybody knows a solution how to do that. If it is possible please insert also links or something else.
Thx!
|
|
|
|
|
hi,
i was wondering, im making an app in vs2005, but when its ready how am i going to convert it so it is an .exe istead of always opening and debugging vs2005
thx
|
|
|
|
|
It already is, open your project directory and take a look in the bin\Debug or bin\Release folders. Note if you want the release version then select the solution node in the Solution Explorer Pane and change Active Config to Release .
Just Google it.
Failing that try phoning
|
|
|
|
|
Hello!
I have been trying to use some of the examples on sorting columns in listviews that are published on for example http://www.codeproject.com/cs/miscctrl/ListViewColumnSorter.asp[^]and some other places but I keep getting this error:
Error 1 Using the generic type 'System.Collections.Generic.IComparer<t>' requires '1' type arguments
I guess it something that has changed with later versions of C# and I wonder if anyone knows how to solve this?
Best regards,
Hampus
|
|
|
|
|
You need provide a generic type argument for your IComparer, e.g.
IComparer<int> comparer = new MyIntComparer(); The <int> bit is the bit you seem to be missing, note this is just an example.
Just Google it.
Failing that try phoning
|
|
|
|
|
Alright, I have my GUI written in C and the other document is in command-line and written in C++. I'd like to merge one code with another on a click of a certain menu item and I do not know how to do so.
My main.cpp looks like this:
#include <windows.h><br />
#define IDR_MYMENU 101//Defines the menu ID<br />
#define IDI_MYICON 201//Defines the Icon ID<br />
#define ID_FILE_EXIT 9001//Defines menu item "Exit"<br />
#define ID_CONVERT_MM 9002//Defines menu item "MessengerMate"<br />
#define ID_CONVERT_MIDDLE 9003//Defines menu item "Middle_Man(Coming Soon..)"<br />
<br />
<br />
const char g_szClassName[] = "myWindowClass";
<br />
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{<br />
switch(msg)<br />
{<br />
case WM_CREATE:
{<br />
HMENU hMenu, hSubMenu;<br />
HICON hIcon, hIconSm;<br />
<br />
hMenu = CreateMenu();<br />
<br />
hSubMenu = CreatePopupMenu();<br />
AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");<br />
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");<br />
<br />
<br />
hSubMenu = CreatePopupMenu();<br />
AppendMenu(hSubMenu, MF_STRING, ID_CONVERT_MM, "&MessengerMate");<br />
AppendMenu(hSubMenu, MF_STRING, ID_CONVERT_MIDDLE, "&Middle_Man(Coming Soon..)");<br />
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Convert to..");<br />
<br />
SetMenu(hwnd, hMenu);<br />
<br />
<br />
hIcon= LoadImage(NULL, "RidV.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);<br />
if(hIcon)<br />
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);<br />
else<br />
MessageBox(hwnd, "Could not load large icon!", "Error", MB_OK | MB_ICONERROR);<br />
<br />
hIconSm= LoadImage(NULL, "RidV16.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);<br />
if(hIconSm)<br />
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);<br />
else<br />
MessageBox(hwnd, "Could not load small icon!", "Error", MB_OK | MB_ICONERROR);<br />
}<br />
break;<br />
case WM_COMMAND:<br />
switch(LOWORD(wParam))<br />
{<br />
break;<br />
<br />
case ID_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);<br />
break;<br />
case ID_CONVERT_MM:<br />
<br />
break;<br />
case ID_CONVERT_MIDDLE:<br />
<br />
break;<br />
}<br />
<br />
break; <br />
case WM_CLOSE:
DestroyWindow(hwnd);<br />
break;<br />
case WM_DESTROY:
PostQuitMessage(0);<br />
break;<br />
default:<br />
return DefWindowProc(hwnd, msg, wParam, lParam);<br />
}<br />
return 0;<br />
}<br />
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,<br />
LPSTR lpCmdLine, int nCmdShow)<br />
{<br />
<br />
WNDCLASSEX wc;<br />
HWND hwnd;<br />
MSG Msg;<br />
<br />
wc.cbSize = sizeof(WNDCLASSEX);<br />
wc.style = 0;<br />
wc.lpfnWndProc = WndProc;<br />
wc.cbClsExtra = 0;<br />
wc.cbWndExtra = 0;<br />
wc.hInstance = hInstance;<br />
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);<br />
wc.hCursor = LoadCursor(NULL, IDC_ARROW);<br />
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);<br />
wc.lpszMenuName = NULL;<br />
wc.lpszClassName = g_szClassName;<br />
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);<br />
<br />
if(!RegisterClassEx(&wc))<br />
{<br />
MessageBox(NULL, "Window Registration Failed!", "Error!",<br />
MB_ICONEXCLAMATION | MB_OK);<br />
return 0;<br />
}<br />
<br />
hwnd = CreateWindowEx(<br />
WS_EX_CLIENTEDGE,<br />
"myWindowClass",<br />
"Alias Converter by Ridv",<br />
WS_OVERLAPPEDWINDOW,<br />
CW_USEDEFAULT, CW_USEDEFAULT, 500, 500,<br />
NULL, NULL, hInstance, NULL);<br />
<br />
if(hwnd == NULL)<br />
{<br />
MessageBox(NULL, "Window Creation Failed!", "Error!",<br />
MB_ICONEXCLAMATION | MB_OK);<br />
return 0;<br />
}<br />
<br />
ShowWindow(hwnd, nCmdShow);<br />
UpdateWindow(hwnd);<br />
<br />
while(GetMessage(&Msg, NULL, 0, 0) > 0)<br />
{<br />
TranslateMessage(&Msg);<br />
DispatchMessage(&Msg);<br />
}<br />
return Msg.wParam;<br />
}<br />
<br />
and I want to incorporate this(da2mm.cpp) into the case ID_CONVERT_MM:
<br />
#include <iostream><br />
#include <fstream>
#include <string><br />
#include "find_daa.cpp"<br />
using namespace std;
<br />
inline string find_daa();
<br />
int main()
{<br />
string da;
<br />
da = find_daa();
<br />
if(da == "-1")
{<br />
cout << "No file was chosen or available for conversion" << endl;<br />
cout << "Program will now exit" << endl;<br />
system("pause");<br />
<br />
return -1;<br />
};<br />
<br />
ifstream daFile(da.c_str(), ios::in);<br />
<br />
if(!daFile)<br />
{<br />
cout << "File could not be opened or does not exist" << endl;<br />
cout << "Program will now exit..." << endl;<br />
system("pause");<br />
<br />
return -1;
};<br />
int pos = daFile.tellg();<br />
<br />
ofstream mmFile("mmaliases.reg");<br />
<br />
if(!mmFile)<br />
{<br />
cout << "File could not be created" << endl;<br />
cout << "Program will now exit..." << endl;<br />
system("pause");<br />
<br />
return -1;
};<br />
<br />
<br />
mmFile << "Windows Registry Editor Version 5.00" << endl << endl;<br />
mmFile << "[HKEY_CURRENT_USER\\Software\\Messenger:Mate\\AIM\\Profiles\\Default\\Aliases]" << endl;<br />
<br />
string sn;<br />
string alias;<br />
<br />
while(!daFile.eof())
{<br />
getline(daFile, sn, '\t');
getline(daFile, alias);
<br />
if(sn.empty() || alias.empty()) continue;
<br />
mmFile << "\"" << sn << "\"=\"" << alias << "\"" << endl;<br />
};<br />
<br />
daFile.clear();
daFile.seekg(pos, ios::beg);
mmFile << endl << "[HKEY_CURRENT_USER\\Software\\Messenger:Mate\\AIM\\Profiles\\Default\\Aliases\\RL]";<br />
mmFile << endl;<br />
<br />
while(!daFile.eof())
{<br />
getline(daFile, sn, '\t');
getline(daFile, alias);
<br />
if(sn.empty() || alias.empty()) continue;
<br />
mmFile << "\"" << alias << "\"=\"" << sn << "\"" << endl;<br />
};<br />
<br />
mmFile.close();<br />
daFile.close();<br />
<br />
system("REGEDIT /S mmaliases.reg");<br />
<br />
system("DEL mmaliases.reg");<br />
<br />
cout << "Thank you for using this conversion program written by: Ridv" << endl;<br />
system("pause");
<br />
<br />
<br />
return 0;
};<br />
and this is the second file(find_daa.cpp) to da2mm.cpp:
<br />
#include <errno.h><br />
#include <dirent.h>
#include <string><br />
#include <cctype><br />
using namespace std;<br />
<br />
string find_daa(void)<br />
{<br />
DIR *dir;
struct dirent *place;
string filename;
string ret;
int result;
char response;
<br />
dir = opendir(".");
<br />
if(!dir){
cout << "Could not open dir";<br />
system("pause");<br />
return "1";<br />
};<br />
errno = 0;
<br />
while(place=readdir(dir))
{<br />
filename.assign(place->d_name);
result = filename.find(".daa", 0);
if(result != string::npos)
{<br />
cout << "Would you like to convert " << filename << " ? [Y/N]" << endl;<br />
cin >> response;
response = tolower(response);
if(response == 'y')
{<br />
ret.assign(filename);
break;
}<br />
};<br />
};<br />
<br />
if(errno)
{<br />
cout << "Problem with readdir";<br />
system("pause");<br />
return "1";<br />
};<br />
if(ret.empty())
{ <br />
return "-1";<br />
}<br />
closedir(dir);
return ret;<br />
}<br />
All this info is just to give you an idea of what I want to do since I'm not too sure what the technical term for the procedure is. Also, whenever I move the installer out of the directory that the icons are in, it'll produce the errors and i'm wondering how to fix it to where no matter where the installer is, it shows the icons. Sorry i'm a newb.
Any help is greatly appreciated and if I have any other code wrong please inform me.
|
|
|
|
|
- Ask in the correct forum[^] for a start.
- Many people don't appreciate having huge amounts of code to look through. If they need to see a bit of the code then they will more than likely ask for it.
mikhailxyohman wrote: I have any other code wrong please inform me.
- Are we your debuggers now?
Just Google it.
Failing that try phoning
|
|
|
|
|
I thought I'd give as much infor as I could and I've tried googling/searching every C#/C++ site to find out how to. I cannot figure out what I would classify my topic as, so I came here for help. I'll get this topic moved.
|
|
|
|
|