|
how can i create a new process in c
|
|
|
|
|
Use the Windows API CreateProcess .
Maxwell Chen
|
|
|
|
|
|
use:
<br />
int system(<br />
const char *command <br />
);<br />
head file: <process.h> or <stdlib.h>
|
|
|
|
|
I'm very rusty - haven't coded C/C++ since 1994 - and I'm sure there's a simple answer, but I can't find it.
I'm not using 'string' support. Just the old char* methods, and the code is behaving well except when I tried to convert a keyboard virtual key code to a it's ascii character I got a runtime access violation.
The 'break' option showed me the site of the infraction - inside some MS code located in the midst of some UNICODE related logic, judging by the Defines.
I included <ctype.h>, but it didn't help.
The related trimmed code follows:
char c;
c = (char)__toascii(keyCode);
keyCode = p->vkCode;
The offending later statement is:
nLen = fprintf(fOut,"kcK=%d ud=%s kc=%d sh=%d ti=%d %s\n",cb.kcK,updn,keyCode,Shift,tick, c);
The following statement works perfectly (as above, but no c at the end)
nLen = fprintf(fOut,"kcK=%d ud=%s kc=%d sh=%d ti=%d %s\n",cb.kcK,updn,keyCode,Shift,tick);
Searched the articles and FAQ but didn't find anything.
Hope you can give me a hand here.
BTW, I want to stay in the char* arena rather than strings, for now.
I'm using Visual C++ 2003 and running Win2K SP4
One more thing - I'm logged in under my old email glyfyx@storm.ca but I have a new address, glyfix@storm.ca. I guess I should change it at Code Project?
Thanks
glyfyx
|
|
|
|
|
If c is a char , you should use %c . That's all.
Maxwell Chen
|
|
|
|
|
|
Mark Salsbery wrote: I forgot about %c....do you need to cast the c argument to an int when it's passed as
an argument for %c?
No, not needed. Simply this way is fine.
char a = 65;
printf("%c \n", a);
Maxwell Chen
|
|
|
|
|
Cool thanks!
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Of course, %c for char! I was sure it had a simple answer but couldn't see it for looking - most embarrassing. Too many years of VB?
So big thanks Maxwell and Mark! Also Mark, I was starting to think of assembling a 2 byte char array as you suggested - that'd work with %s.
Also special thanks to Rajkumar R for the ToAscii suggestion, which is intriguing to say the least, since it requires a GetKeyboardState call to set its 256 byte array arg, lpKeyState, to the current status of *all* the virtual keys. I would have thought GetKeyState for just the virtual key in question (1st arg, uVirtKey),would be sufficient.
I suppose ToAscii will be a case-sensitive conversion - will give it a shot and see what happens.
int ToAscii(
UINT uVirtKey,
UINT uScanCode,
PBYTE lpKeyState,
LPWORD lpChar,
UINT uFlags
);
Here's the MSDN article...
http://msdn2.microsoft.com/en-us/library/ms646299(VS.85).aspx
Thanks again everyone!
glyfyx
|
|
|
|
|
glyfyx wrote: I tried to convert a keyboard virtual key code to a it's ascii character
if you are converting from Keyboard Virtual KeyCode, use
int ToAscii(
UINT uVirtKey,
UINT uScanCode,
PBYTE lpKeyState,
LPWORD lpChar,
UINT uFlags
);
glyfyx wrote: The offending later statement is:
nLen = fprintf(fOut,"kcK=%d ud=%s kc=%d sh=%d ti=%d %s\n",cb.kcK,updn,keyCode,Shift,tick, c);
format specifier is %s and passing char, c.
|
|
|
|
|
The arguments you pass to fprintf() need to match the format specifiers in the
format control string, in both type and number of arguments.
All the "%d"s in the format control string need a corresponding 32-bit integer argument passsed...
All the "%s"s in the format control string need a corresponding pointer to a null-terminated string passed.
The version where you don't pass the c argument only appears to work, since you pass 5 arguments
when the format control string specifies an expected 6 arguments.
The version that crashes probably fails because c is a char but the format specifier is %s, which means
the passed argument should be a pointer to a NULL-terminated string, not a single character.
If you do something like this, it should work:
char c<font color="Red">[2]</font>;
c<font color="Red">[0]</font> = (char)__toascii(keyCode);
<font color="Red">c[1] = '\0';</font>
keyCode = p->vkCode;
...
nLen = fprintf(fOut,"kcK=%d ud=%s kc=%d sh=%d ti=%d %s\n",cb.kcK,updn,keyCode,Shift,tick, c);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In Button event I wrote ...
CMatlabEng matlab;
matlab.Open(NULL);
But MatLab is not opening .....Plz Help me.........
#sanroop#
|
|
|
|
|
like this way i fallow ...
Open MSVisualC++.
Select Tools ->Customize from the MSVC menu.
Click on the Add-ins and Macro Files tab.
but MATLAB for Visual Studio on the Add-ins and Macro Files list is not showing...PLZ help me...How to Configure the Matlab Add-in for Visual Studio vc++ 6.0..PLZ
#sanroop#
|
|
|
|
|
Hi all
I am locking a file.First times it locks..but second time if i want to unlock..it is not unlocking the file..plz help me ..here is the code....
int LockFile(char *cFileName, bool bLock)
{
int iFile;
if(bLock)
{
iFile = _open(strcat(cFileName, ".lck"), _O_CREAT | _O_EXCL | _O_RDWR);
_close(iFile);
if(iFile < 0)
{
printf("File locked by another process");
return -1;
}
printf("File is locked for writting");
return iFile;
}
else
{
iFile = remove(strcat(cFileName, ""));
if(iFile == -1)
{
printf("Error in file unlocking");
return -1;
}
printf("File unlocking successfull");
}
return iFile;
}
int main(int argc, char* argv[])
{
char strFilePath []= {"E:\\Add_Modified_ENG\\test.txt"};
char *cFilePath = strFilePath;
int i = LockFile(strFilePath, true);
if(i != -1)
{
ofstream outfile(cFilePath, ios::app);
if(!outfile)
{
cout<<"Unable to open\n";
return 1;
}
outfile<<"Test";
outfile.close();
}
i = LockFile(strFilePath, false);
return 0;
}
Hi,,
I am sharan.Working as a software Engineer in Indo-Fuji Software Company located in BTM Layout.Bangalore.India.
I have Completed my B.E(COmputers)in 2006.ANd I am having 2 years of Exp in VC++.
thanking you
sharan
|
|
|
|
|
I think you are creating a lock file; You are not locking a file.
sharanu wrote: iFile = _open(strcat(cFileName, ".lck"), _O_CREAT | _O_EXCL | _O_RDWR);
and
sharanu wrote: iFile = remove(strcat(cFileName, ""));
file names are different isn't it?
|
|
|
|
|
File names are same..in first
iFile = _open(strcat(cFileName, ".lck"), _O_CREAT | _O_EXCL | _O_RDWR);
I am caoncated the(.lck)i.e is locking the file...
In second i am remove the lock
iFile = remove(strcat(cFileName, ""));
Hi,,
I am sharan.Working as a software Engineer in Indo-Fuji Software Company located in BTM Layout.Bangalore.India.
I have Completed my B.E(COmputers)in 2006.ANd I am having 2 years of Exp in VC++.
thanking you
sharan
|
|
|
|
|
yes, i just looked at LockFile function only, But then you are accessing the array beyond its size
char strFilePath []= {"E:\\Add_Modified_ENG\\test.txt"}; concatenation causes corrupted stack;
Any way your problem is you are creating the file in Read only permission, so remove(), DeleteFile() won't work unless you change the readonly attribute of the file.
try this.
iFile = _open(strcat(cFileName, ".lck"), _O_CREAT | _O_EXCL | _O_RDWR, _S_IREAD | _S_IWRITE);
|
|
|
|
|
Hi its not working .....
It is printing as "Test" in File
Hi,,
I am sharan.Working as a software Engineer in Indo-Fuji Software Company located in BTM Layout.Bangalore.India.
I have Completed my B.E(COmputers)in 2006.ANd I am having 2 years of Exp in VC++.
thanking you
sharan
|
|
|
|
|
Now u are able to call the remove() successfully, Isn't it.
What you are trying to achieve? i already told change the read only attribute before remove().
_chmod() / SetFileAttributes() to change the readonly attributes.
If you want to lock a file, LockFile() / _locking()/_lock_file() API is there.
|
|
|
|
|
Hi,
I have changed the background color of my CToolBar. Now I would like to change the background color CToolBar's parent window which is AfxControlBar*. How could I do this ?
Any help would be appreciated.
Thanks,
Paresh
|
|
|
|
|
What exactly you trying to do??
Anyways simple way to change background color is Handle WM_CTLCOLOR message and return a brush of new color.
|
|
|
|
|
Hi Sandip,
I want to paint the background color of the CToolbar. However, I am able to paint only the area which belongs to CToolbar and not the AfxControlBar, which is the parent of CToolbar. (though we have a m_wndToolbar as a member of CMainFrm).
I hope you understand the issue.
Regards,
Paresh.
|
|
|
|
|
dear all
i would like to generate several different Gaussian function according to different sigma,and then can determine x and y value(ie. bound), and then it can determine the size of Gaussian mask. the formula is below: it is Gaussian function: g(x,y)=1/2*3.14*exp(-(pow(x,2)+pow(y,2)))/2*pow(sigma,2)
thanks a lot.
Li Zhiyuan
|
|
|
|
|
I want to continuously poll one of the pins of my parallel port for activity. I've written a function to do this, but I can't find where to call the function. Every place I place the function call, it executes before my SDI page appears. I want to use an SDI environment so I can print out the data stream detected on the port pin. How do I implement my function???? Signed/Confused!
|
|
|
|
|