|
Look at FindFirstFileW() and FindNextFileW()
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I had been playing around with FindFirstFileW but couldn't get it work. Here's the code I've dabbled using.
Does anyone have a link or small clip of code including #includes that works?
//THIS CODE DOESN'T WORK
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
WIN32_FIND_DATAW FindFileData;
LPCWSTR lpFileName = (const unsigned short *) "*";
HANDLE hFind;
ofstream outfile("new.txt");
hFind = FindFirstFileW(lpFileName, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
printf ("Invalid File Handle. GetLastError reports %d\n",
GetLastError ());
return (0);
}
else
{
printf ("The first file found is %s\n", FindFileData.cFileName);
while (FindNextFileW(hFind, &FindFileData) != 0)
{
printf ("Next file name is %s\n", FindFileData.cFileName);
outfile << FindFileData.cFileName << endl;
}
FindClose(hFind);
return (1);
}
}
|
|
|
|
|
stvprg wrote:
LPCWSTR lpFileName = (const unsigned short *) "*"
That's the problem. You're assigning a non-unicode string constant to a unicode string pointer. You need to use a true unicode string:
LPCWSTR lpFileName = L"*";
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Thank you, that L"*" suggestion really worked well. That solved the problem with getting the file handle that FindFirstFileW returns.
I tried all yesterday using TCHAR, turning binary write mode on/off and all sorts of unconventional programming methods to put FindFileData.cFileName into an array and/or file without success.
Try not to laugh but the closest I came to writting something close to unicode text with iostream was from the following code.
TCHAR tch = ' ';
int x=0;
while ((tch=FindFileData.cFileName[x])!=0)
{
outfile.put(FindFileData.cFileName[x++]); }
outfile << endl;
I've even tried outfile.put(tch) and outfile << etc every way I could imagine to try to write this to a file. I got alot of interesting files and even some close ones where the ascii chars read okay but the unicode multilangual chars were wrong, probably because they were being truncated or cut from a 4 3 2 byte into a 1 byte char.
I'm trying to write a simple console program.
How can I get the unicode TCHAR written onto a file using ofstream? Or is there a simpler way of doing this.
|
|
|
|
|
stvprg wrote:
How can I get the unicode TCHAR written onto a file using ofstream? Or is there a simpler way of doing this.
Use wofstream , which is the unicode version of ofstream , and then you can just write unicode characters as you would normal characters with a standard ofstream .
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I am developping a special software in Visual C++.
The algoritm-result consists of several rectangular solids (packs).
These packs should now be represented graphically.
I have the data of the coordinates (x,y,z) of the corners of all the packs that should be represented. The packs can be have different sizes, but have all rectangular surfaces. There can be a unlimited number of packs in the result.
The surfaces of each pack must be presented in an own color.
So I look for a dll or for an OpenGL / Glut / C++-Sourcecode that manages the 3D-presentation automatically out of the coordinate-data (input) of each pack. The dll / code must handle automatically the coverage of a pack by other packs, so that only the sight of a special perspective is shown.
The user must be able to spin / turn / rotate the whole sight to any direction (all axis of rotation).
I am sure that this problem has been solved already by other developpers. But where can I found such a dll / Sourcecode ? Can anybody give me an advice please ?
|
|
|
|
|
Google for Nehe. His OpenGL tutorials probably contain all the code you need to do this, as well as a sample C++ MFC project that's set up for OpenGL.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
i have this header for my class file and then .....
#include<vector>
using namespace std;
class bigNumber;
bigNumber operator +(const bigNumber& lhs, const bigNumber& rhs);
bigNumber operator -(const bigNumber& lhs, const bigNumber& rhs);
bigNumber operator *(const bigNumber& lhs, const bigNumber& rhs);
ostream& operator<< (ostream& ostr, const bigNumber& t);
istream& operator>> (istream& istr, bigNumber& t);
class bigNumber{
public:
bigNumber();
bigNumber(const string & s);
bigNumber(vector<int> v);
friend bigNumber operator +(const bigNumber& lhs, const bigNumber& rhs);
friend bigNumber operator -(const bigNumber& lhs, const bigNumber& rhs);
friend bigNumber operator *(const bigNumber& lhs, const bigNumber& rhs);
friend ostream& operator<< (ostream& ostr, const bigNumber& t);
friend istream& operator>> (istream& istr, bigNumber& t);
private:
vector<int> digits;
void reverse ();
};
i have these member functions coded so far but i need help with the input operator
bigNumber::bigNumber(){
}
bigNumber::bigNumber(const string& s){
for(int i= 0; i < s.length();i++)
digits.push_back(s[i] - '0');
}
bigNumber::bigNumber(vector<int> v){
for(int j = 0; j < v.size(); j++)
digits.push_back(v[j]);
}
bigNumber operator +(const bigNumber& lhs, const bigNumber& rhs){
return 0;
}
bigNumber operator -(const bigNumber& lhs, const bigNumber& rhs){
return 0;
}
bigNumber operator *(const bigNumber& lhs, const bigNumber& rhs){
return 0;
}
ostream& operator<< (ostream& ostr, const bigNumber& t){
for(int k = 0; k < (t.digits).size();k++)
ostr << t.digits[k];
return ostr;
}
istream& operator>> (istream& istr, bigNumber& t){
istr >> t.digits;
return istr;
}
when i leave the input operator like it is i get an error saying
error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::vector<int,class std::allocator<int=""> >' (or there is no acceptable conversion)
i dont know how to fix this and i am really pressed for time can someone please help me?
|
|
|
|
|
You can't do that. You need to iterate through the vector as you did for the output stream and pass each object through.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
char d;
if(istr >> d && isdigit(d))
t.digits.push_back(d - '0');
istr >> noskipws;
while(istr >> d && isdigit(d))
t.digits.push_back(d - '0');
istr >> skipws;
how come i keep getting the vector before added to the next vector if i input two numbers
??
|
|
|
|
|
d - '0' is a hack. Use atoi(d) instead.
What's going wrong ? Have you tried stepping through the code ? Why are you setting skipws instead of checking what the value of the flag is before you start ( so that you never change the state of the stream ) ? Why are there no brackets in the above code ? I'd expect you to just use a while loop for the entire code, not have the if at the start, and I'd expect all of the above code to be within the while loop, so if the first character is not a digit, none of it would run.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
my professor wants it the way that i have it right now. the reason is because you may press the enter key before inputting a number and it will still pickup the number.
that works, i figured out that i was missing a while loop. now it works fine and i am on to the arithmetic operators which i am having some trouble with.
thanks for all your help
very appreciative.
|
|
|
|
|
Anonymous wrote:
my professor wants it the way that i have it right now. the reason is because you may press the enter key before inputting a number and it will still pickup the number.
The initial character check, or the hack to use - '0' ?
Anonymous wrote:
that works, i figured out that i was missing a while loop
You're using a while loop to step through the vector ?
Anonymous wrote:
which i am having some trouble with.
Yeah, they are probably the stickiest bit, the iostream operators were pretty simple by comparison.
Did you read my iostream inserter/extractor article ? I forget the details, but there's definately stuff missing to make your code as good as it could be.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I've made an OCX control. It works fine OK.
I want to instanciate that OCX when a .fbx file is dropped from file explorer on an Office application ... How can I do that?
Ex: In a PowerPoint slide I want to drop from file explorer myfile.fbx and this will instanciate
my FbxViewer.ocx in the PP slide and myfile.fbx will be loaded into my OCX control.
thanks
Danny
|
|
|
|
|
Can someone recommend a "Menu with icons" implementaiton that:
- works with MFC and ATL / WTL
- is least intrusive as possible
- works in both "classic" and "XP" look
I'd go with the "native" (MENUITEMINFO.hbmpItem, however, it looks terribly ugly)
There's an MFC solution here that loads a toolbarresource, and matches it with the ID's which I consider fairly clever, however it's MFC only and doesn't react lightly to changing the menu on the fly.
Suggestions?
Pandoras Gift #44: Hope. The one that keeps you on suffering. aber.. "Wie gesagt, der Scheiss is' Therapie" boost your code || Fold With Us! || sighist | doxygen
|
|
|
|
|
For some reason "status" field of Win32_Thread I am getting ThreadID. According to MS it should be status there like "OK", "Error", "Unknown", but I get in BSTR thread ID number. Just surprise is correct?
Thanks.
Alex.
|
|
|
|
|
I'm not sure where else to ask this so hear goes.
I have a file of about 14k in size. Its an Altera file to program an fpga.
I need to essentially split the file into chunks of 64 bytes, so I can use a specific function to send it through a usb device to our fpga.
Soooo how can I split a file of any size into chunks of 64 bytes?
|
|
|
|
|
By using an ifstream and an ofstream, just read 64 bytes at a time, and write off to files of your choosing.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How can I make a C++/MFC (Version 6) application use the "Windows classic" look when running under Windows XP?
Thanks,
Alan
|
|
|
|
|
You shouldn't need to do anything special to make this happen.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
But when I run the application on XP, it uses the XP look: Blue shaded scroll bars (instead of the classic gray), faint group-box lines, etc...
It's possible to force an application to use the XP style. What I need is the opposite: Forcing the application to use the classic style.
Alan
|
|
|
|
|
Does the .exe contain an embedded manifest resource or an accompanying manifest file? See this[^] link (specifically the topic "To create a manifest and enable your application to use visual styles").
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Thanks for the link, Ravi, but this seems to show how to force the application to use the XP visual style, which is the opposite of what I'm trying to do. Do you know how to modify this to use the Windows classic style?
Thanks,
Alan
|
|
|
|
|
Hi All,
Ok, this should be easy to figure out, but I can't seem to google a good answer. I need a way to programmatically discover the path to the current user's desktop. Something similar to GetWindowsDirectory() or GetSystemDirectory(), I guess.
The only think I could find was VBScript stuff like WshShell.SpecialFolders(...) or using the Windows Shell COM stuff.
There must be a simpler way to do this in C++, no?
TIA,
Pete
|
|
|
|
|
How about SHGetFolderPath(..., CSIDL_DESKTOPDIRECTORY, ...) ?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|