|
out put was the same... I typed "the quick red fox jumped over the lazy brown dog" and it all went into szBuffer. Maybe its not as obvious as I thought, I just figured I was getting a bit fuzzy in the head as I've been in at it since 9am with just a two hour dinner break.
---------------------------------------------
Be good! But if you can't be good, at least be good at it and try not to get any on ya!
-mjf
|
|
|
|
|
Something is definitely looping and reading the data. Otherwise, maybe the COM part of the implementation dynamically expands szBuffer to accommodate the data.
Kuphryn
|
|
|
|
|
This code makes me shiver. Should you be checking each character of szBuffer for >? Does Read ever set dwBytesRead to the required buffer size that's available in the queue? Try adding ASSERT() after read to be sure.
do
{
if (eEvent & CSerial::EEventRecv)
{
DWORD dwBytesRead = 0;
char szBuffer[10];
do
{
lLastError = serial.Read(szBuffer, sizeof(szBuffer)-1, &dwBytesRead);
ASSERT(dwBytesRead < 10);
if(lLastError != ERROR_SUCCESS)
return ShowError(serial.GetLastError(), _T("Unable to read from COM-Port"));
if(dwBytesRead > 0)
{
if (szBuffer[dwBytesRead-1] == '>')
fContinue = false;
}
} while (dwBytesRead == sizeof(szBuffer)-1);
}
} while (fContinue);
Todd Smith
|
|
|
|
|
nope.. the ASSERT didn't catch it either - ggrrrr! AT this stage I'm just using 10 as an arbitrary value that doesn't take a long time for me type out from the sending machine. In practice, I will have no idea of the sizeof the incoming data persay. Actually, I will be testing the first few characters and then know the size (there are several different formatted messages coming in of different but known sizes and I want to make sure it breaks not only on the '>' but on a full szBuffer (for any case where the '>' didn't get sent)
---------------------------------------------
Be good! But if you can't be good, at least be good at it and try not to get any on ya!
-mjf
|
|
|
|
|
Oh. How are you determining that szBuffer has more than 10 bytes in it? Try this
change
DWORD dwReadBytes;
char szBuffer[10];
do
{
Read();
}
to
do
{
DWORD dwReadBytes;
char szBuffer[10] = {0};
Read();
}
Todd Smith
|
|
|
|
|
well.. your question regarding how i'm checking szBuffer got me thinking and I've determined that dwBytesRead is always 1 so I'm gonna have to take a good look at that. As to how I am actually checking- good question- had a line in there that was concat-ing szBuffer[dwBytesRead-1]to another string that was being displayed else where in code. You can see the problem with that knowing dwBytesRead is always one - so it wasn't szBuffer that was gettign the extra memory after all. Writing the code at you have it here required the do/while condition to be redone as well... thinking it might be a good idea to approach this with a more alert mind so I'm packing in the VC for the night - but thanks for the input and if you happen to think of anything else send it over - it cant hurt.
Thanks
-Mel
---------------------------------------------
Be good! But if you can't be good, at least be good at it and try not to get any on ya!
-mjf
|
|
|
|
|
i want to run a perticuler registry key how to run it any body could tell the sample code
i will be very thank full to u?
r00d0034@yahoo.com
|
|
|
|
|
what do you mean ? you don't 'run' a registry key.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
thanks for replay.
infect i want to uninstall a software that appear in add/remove program.
then i can go to registry
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
and look for uninstallString key.
The Sub keys of the key i mention contain a REG_SZ:Uninstallstring. i just need to run that.
but in a program how to find it and run it?
plzz help
if u could write sample code.
plzzzzzz
r00d0034@yahoo.com
|
|
|
|
|
Ah - that's different. You want to read a string from the registry. There are at least two classes with sample code to do this on CP.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
what do u mean by CP?
and what those classes are?
r00d0034@yahoo.com
|
|
|
|
|
Um... Code Project. You're not really cut out for this, are you ?
At least one of them is called CRegistry.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
These keys are the properties of the installed applications. (Content of the Add/Remove programs Windows panel).
It is highly recommended not to do anything with them. You can corrupt things a bit.
Applications often use InstallShield to install, and they create such keys to help the Uninstaller do his job when the user decides to remove the program. In the case of InstallShield, the Uninstaller is a separate program (IsUninst.exe) installed along with the program, and it uses the content of these keys as cmdline parameters.
In short, leave this alone!;)
How low can you go ? (MS rant)
|
|
|
|
|
There are solution solution to read in a registry key.
Win32 API:
RegOpenKey()
RegOpenKeyEx()
MFC:
GetProfileString()
As for uninstallation, you can use an uninstaller such as InstallShield or design your own uninstaller.
Kuphryn
|
|
|
|
|
what do you mean by this?
As for uninstallation, you can use an uninstaller such as InstallShield or design your own uninstaller.
infect i want to uninstall programatically any software with out any user interaction?
r00d0034@yahoo.com
|
|
|
|
|
Okay.
You cannot programmably uninstall an application if it was installed using some other vendor's installer such as InstallShield. One reason is you would have to read and understand InstallShield's logfile.
Another solution is if the registry key list some uninstall executable line "unwise.exe," then you can execute that file.
HINSTANCE ShellExecute(HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd)
UINT WinExec(LPCSTR lpCmdLine, UINT uCmdShow)
Kuphryn
|
|
|
|
|
Or CreateProcess()
Todd Smith
|
|
|
|
|
I'm working on a program which is not allowed to be run more than once in same directory, but is allowed to be run as many times as users want if the programs are located in diffrent directory. For example, suppose my program is named "abc.exe":
run c:\path1\abc.exe -> OK
run c:\path1\abc.exe -> Not OK
However:
run c:\path1\abc.exe -> OK
run c:\path2\abc.exe -> OK
run c:\path3\abc.exe -> OK
I wish I explained clear enoguh in above scenario. Now, to accomplish this, I thought using mutex should be good, this is how I did:
In beginning of the program I use GetModuleFileName to obtain application path and store it in a string, say g_szAppPath , and I use this string to create MUTEX object. Hmm, I thought it should work since g_szAppPath would only be different if the programs are located in different directory, is it not? But somehow this method does not work, I can always run the program multiple times in same directory.
What am I doing wrong? Is there a good way to get what I want? Thanks guys.
|
|
|
|
|
errrrrr
getcurrentdirectory() ?
"even if my world is weird it's my world" biz stuff about me
|
|
|
|
|
it is very easy, save running exes in a file or register, check before a new exe runs.
includeh10
|
|
|
|
|
This is what I would try:
CString strFile;
::GetModuleFileName(NULL, strFile.GetBuffer(MAX_PATH), MAX_PATH);
strFile.ReleaseBuffer();
CMutex(FALSE, strFile);
if (::GetLastError() == ERROR_ALREADY_EXISTS)
return FALSE;
static CMutex mutex(FALSE, strFile);
[edit]Put this in your InitInstance and try it.[/edit]
Regards,
Alvaro
There is much pleasure to be gained from useless knowledge. - Bertrand Russell
|
|
|
|
|
Thank you. I tried but got runtime error as shown below:
--------------------------------------------
Microsoft Visual C++ runtime library error:
Program: c:\blahblah\blah.exe
Abnormal program termination.
---------------------------------------------
Don't know what's wrong...
|
|
|
|
|
Yep, I tried it and it blew up on me too. For some reason it didn't like the name of the mutex (with the backslashes). I replaced the backslashes with regular slashes and it works like a champ. I also changed to code to be a little simpler:
CString strMutex;
::GetModuleFileName(NULL, strMutex.GetBuffer(MAX_PATH), MAX_PATH);
strMutex.ReleaseBuffer();
strMutex.Replace('\\', '/');
static CMutex mutex(FALSE, strMutex);
if (::GetLastError() == ERROR_ALREADY_EXISTS)
return FALSE;
Regards,
Alvaro
There is much pleasure to be gained from useless knowledge. - Bertrand Russell
|
|
|
|
|
YES man! Finally!
OK it works perfectly now, so the real trick is that we cannot have back-slashes in a mutex name, damn it, where in MSDN said that?
Thank you a lot.
Bin
|
|
|
|
|
i saved lparam and wparam values when a key
(say U)pressed on a perticuler edit box.
i want to use these values of lparam and wparam again on different edit box.in order to see that key
(say U) .
is that code is correct or not for that purpose?
is there any change in logic if yes then plz tell?
LPEVENTMSG lpEvent= (LPEVENTMSG)lParam;
PostMessage(different_hWnd,
lpEvent->message,wParam,lParam);
r00d0034@yahoo.com
|
|
|
|