|
Jack Squirrel wrote:
Is there a similar function in Win32 or MFC?
How about GetCPInfo() ?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Doesn't work.
I'm extracting the encoding attribute from an XML file, afterwhich I need to figure out which Windows code page is needed to convert the text to Unicode.
In theory:
<br />
UINT AfxCharacterEncodingToCodePage(LPCTSTR lpszCharacterEncoding)<br />
{<br />
if (_tscicmp(lpszCharacterEncoding, _T("utf-7") == 0)<br />
return (65000);<br />
...<br />
<br />
}<br />
<br />
...<br />
<br />
CString strExtractedCharacterEncoding = _T("utf-7");<br />
<br />
UINT nCodePage = AfxCharacterEncodingToCodePage(strEncoding);<br />
MultiByteToWideChar(nCodePage, blah...);<br />
<br />
I found this list of encodings and their associated code pages, I just don't want to write a function for this if it already exists.
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
The IMultiLanguage2 Interface might be of help.
Interface Information
Stock Implementation: mlang.dll
Custom Implementation: No
Inherits from: IUnknown
Header and IDL files: mlang.h, mlang.idl
Minimum availability: Internet Explorer 5
Minimum operating systems: Windows 95, Windows NT 4.0, Windows CE 4.0
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
I'm writing a small VC++ program that works with a single dialog, and I wanted the buttons inside the window to move position, when the user resizes the window, but I don't know how to do that. I know that I must use the Resize message of the window, and then move the buttons to the right position , using some arithmetics, but I don't know how to move buttons from place at runtime. Could you help me?
|
|
|
|
|
Check this [^]article and see if that helps you.
Artificial intelligence is no match for natural
stupidity.
Never argue with an idiot. They will drag you down to their level where they are an expert.
|
|
|
|
|
Thanks, I didn't know I could find supperior inteligence here. I thought I could only find it in some mudhole in Mars.
|
|
|
|
|
I am working with a tree control on a dialog i created. The following code is how i set up the tree in the OnInitDialog() (m_SectionTree is the name of my control):
TVINSERTSTRUCT tvInsert;
tvInsert.hParent = NULL;
tvInsert.hInsertAfter = NULL;
tvInsert.item.mask = TVIF_TEXT;
tvInsert.item.pszText = _T("Circular");
HTREEITEM hCircular = m_SectionTree.InsertItem(&tvInsert);
m_SectionTree.InsertItem(_T("Circular 1"), hCircular, TVI_SORT);
m_SectionTree.InsertItem(_T("Circular 2"), hCircular, TVI_SORT);
etc....
But when i use the program and colapse part of the tree and then try to redraw it again it doesnt redraw correct. It just freezes and redraws the control in a completely random way.
How do i fix this?
thank you
|
|
|
|
|
I am creating a little setup console application in C++. The application is called from autorun on a cd-rom. Once called, the application opens an html page and wait for the html page to be closed and start another setup program. The problem I have is that when someone accidentally eject the CD and reinsert it, the same html page is launch again. Is there a function that I can call to see if the html file is already opened and not open another html file if the first one is still open? I open the html page using ShellExecuteEx(), wait for the page to be closed using WaitForSingleObject(), and launch the second setup program using CreateProcess(). Any help would be appreciated, thanks.
|
|
|
|
|
What happens if you try and open the .html file using OpenFile(..., OF_SHARE_EXCLUSIVE) ? If that fails then you know the file is already open.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Detect that the CD was ejected and then automatically close the web page.
If they re insert it then it re-starts the process.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
How do I detect that the CD was ejected and what can I use to close the file with? Right now my code looks like this:
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si)); // Zero out STARTUPINFO structure.
si.cb = sizeof(si); // Get size of STARTUOINFO structure.
ZeroMemory(&pi, sizeof(pi)); // Zero out PROCESS_INFORMATION structure.
// Set up SHELLEXECUTEINFO structure.
SHELLEXECUTEINFO sInfo = {0};
sInfo.cbSize = sizeof(SHELLEXECUTEINFO);
sInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
sInfo.hwnd = NULL;
sInfo.lpVerb = "open";
sInfo.lpFile = Path;
sInfo.lpParameters = "";
sInfo.lpDirectory = NULL;
sInfo.nShow = SW_SHOWMAXIMIZED;
sInfo.hInstApp = NULL;
if (!ShellExecuteEx(&sInfo))
{ // Print error message if ShellExecuteEx failed.
printf("ShellExecuteEx failed (%d).\n", GetLastError());
} // Print error message if ShellExecuteEx failed.
WaitForSingleObject(sInfo.hProcess, INFINITE); // Wait for hta window to be closed.
if (!CreateProcess(0, Path, 0, 0, FALSE, NORMAL_PRIORITY_CLASS, 0, 0, &si, &pi))
{ // Print error message if CreateProcess failed.
printf("CreateProcess failed (%d).\n", GetLastError());
} // Print error message if CreateProcess failed.
|
|
|
|
|
The other process may not really have the file open anymore, it could have read it into memory and closed it.
The one question I have though is if the CD is removed, can you continue your installation? If so, then perhaps the single instance check that Blake Miller proposed is all you need. If not, then I'm not saying you shouldn't implement that you probably should implement that either way, however if it is an issue that you can't continue your installation after the CD was ejected, then I would pop up an error message "CD Ejected, Installation Canceled" and you could even make it a modal parent of the application you just launched.
To close the application is a tough one. The simplest method is simply "TerminateProcess", but that's a rough one and usually a last resort. There is a support article on MSDN that specifies the steps you could do to attempt to shut down an application peacefully.
Terminate an application cleanly[^]
You could do a simple polling to check if a file is on the CD until it fails, but that is kind of ugly. I haven't looked into seeing if there is a callback I would search the windows messages or perhaps WM_DEVICECHANGE may even work.
Registration for device Removals[^]
Alternatively, you could lock the drive so you can't eject then re-enable it after you're done.
Check this URL out for all the IOCTLs:
Locking the drive from being ejected[^]
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
While our setups were waiting for another program to finish, we created a special mutex.
If your AutoRun saw that this special mutex existed, then we did not launch our setup again. We assumed it was still running. Our setup ALSO checked for this mutex, in case the user accidentally started the setup program twice. Either way, it works well enough for not allowing your setup program to be running more than once. You can look at some of the 'limit program to a single instance' examples here on CodeProject.
|
|
|
|
|
i rying to code project provided here about process monitoring but it doesn't work i don't now may be th .dll or psapi.h ,psapi.lib ,kernal32.h
not working so th program not working if someone can help me by sending me this files..
this link is the project
http://www.codeproject.com/threads/A_not_so_simple_firewall.asp[^]
|
|
|
|
|
|
thanks''
if u can help i need another implementation of "process monitorer"
that one i couldn't anderstand easily..
plz
i need to know how to alow any process to start or not;;
|
|
|
|
|
Thank you for helping me out before with LPCTSTR, I understand it much better now, and I can get the visual c++6 to complie my program now. Some of the samples I recieved didn't work, and don't know why.
The PROBLEM:
Everytime I send a set of characters over the COM-port, and what I get on the display is: "?????????a" where a is the character I pressed last. I understand that ? means unknown value in the array, but why? Doesn't the program incrament the array and fill in it's unknows? If I set the array to some values, it will display those values, and overwritting the last character.
What am I doing wrong?
My aim is to catch the individual characters that are send to SortData(pszData)in a temporary buffer, and then filter the data that is recieved, and Display it on screen.
int i=1;
void CChildView::SortData(LPCTSTR pszData)
{
TCHAR buffer[1024];
_sntprintf(buffer, 1024, _T("%s"), pszData);
TCHR tempData[10];
tempData[i]=buffer[0];
if (i == 10)
{
i=0;
TCHAR buffer2 [1024];
_sntprintf(buffer2, 1024, _T(%"s"), tempData);
DisplayData(buffer2);
}//end if
i++;
}//end SortData
A computer virus is a program that
will make copies of itself in the memory of a computer, and will transfer
itself to other computers. Thus it fits the definition of a living system. Like a biological virus, it is a rather degenerate form,
because it contains only instructions or genes, and doesn't have any
metabolism of its own. Instead, it reprograms the metabolism of the
host computer, or cell. Some people have questioned whether viruses
should count as life, because they are parasites, and can not exist
independently of their hosts. --Stephen Hawking
|
|
|
|
|
First, I would recommend that you stop using _sntprintf for doing a simple string copy. Use _tcsncpy , that is what it exists for.
Second, if you end up copying the full amount of your buffer, you will not get a NUL terminator, and attempting to treat the contents of the buffer as a normal string may cause you problems.
The code you posted has a typo/bug in the second call to _sntprintf , the format string is incorrect.
The contents of tempData are undefined - it looks like you are assigning a value to the array starting at the second location in the array (1, instead of 0), and you are not NUL terminating the array before treating it as a string.
If you are trying to display the first 10 characters of any data that comes into the function, then you do not need the first string copy (or the buffer buffer), nor the tempData buffer. You can do something like:
void CChildView::SortData(LPCTSTR pszData)
{
TCHAR buffer[ 16 ];
_tcsncpy( buffer, pszData, 10 );
buffer[ 10 ] = _T( '\0' );
DisplayData( buffer );
} If that is not what you are trying to do, I misunderstand both your post and your code.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
James R. Twine wrote:
First, I would recommend that you stop using _sntprintf for doing a simple string copy. Use _tcsncpy, that is what it exists for.
It's recommended that someone should stop using all the unsafe functions from the C libraries and start using the C++ library! I was also using C functions for formatting strings and such, but found that using the C++ stringstreams have more flexibility and are more elegant and fool proof than their C equivalants.
A better code example would be:
void CChildView::SortData(LPCTSTR pszData){
std::string sData(pszData);
DisplayData( sData.c_str() );
}
Utilizing the STL is better if performance is not a big issue, since it is less error prone that using straight C.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Would this work:
std::string sData(pszData);
if pszData is NOT NUL terminated?
I think the reason the _tcsncpy was used was because the input was not guaranteed to be NUL terminated.
|
|
|
|
|
pszData should be NULL terminated! If it's not, you are in big trouble!
The reason why pszData is NULL terminated, is because the name says it. p(ointer)s(tring)z(ero terminated)Data implies that the string is NULL terminated.
Also, all strings in C / C++ are NULL terminated, unless it's explicitly stated. So if pszData is a string like anything else, it's NULL terminated. If it's a buffer from something, it sould not be called a string. You should track down the origins of the string and go from there.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Those functions are safe as you are allowed to present a character count to the API. The unsafe ones are the ones that do not allow this, such as gets(), strcpy(), sprintf().
And I would never reccomend using C++ on even my worst enemy!
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
Toby Opferman wrote:
Those functions are safe as you are allowed to present a character count to the API. The unsafe ones are the ones that do not allow this, such as gets(), strcpy(), sprintf().
They are unsafe in the sense that you have to manage the amount of data that you use. The "safe" classes however do this for you.
Toby Opferman wrote:
And I would never reccomend using C++ on even my worst enemy!
Why is that?
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
I would hope that a programmer is capabile of managing program resources!
Well, I'm not a fan of C++ for many reasons; but I don't want this to get into a religious battle
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
Toby Opferman wrote:
I would hope that a programmer is capabile of managing program resources!
I can only say that practice makes perfect. And with C++, some people need a lot of practice...
Toby Opferman wrote:
Well, I'm not a fan of C++ for many reasons; but I don't want this to get into a religious battle
I read some of your tutorials on debugging and I think that if you are a fan of something, it must be assembler. And C++ makes assembler just a little bit harder to understand doesn't it?
You are spending some time here on the VC++ forum and if you are not a fan of C++, what are you a fan of I wonder?
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|