|
|
Does anyone have any examples on how to use the readfile() function. This is my first time to use it and I'm taking the instructions straight from MSDN and it's not working. Here is what I have.
HANDLE fptr;
bool bResult;
LPVOID inBuffer;
DWORD nBytesToRead = 20;
LPDWORD nBytesRead = 0;
bResult = ReadFile(fptr, &inBuffer, nBytesToRead, nBytesRead, NULL);
I don't think I fully understand how the function works.
|
|
|
|
|
There are many problems with the code you posted... these parts are OK:
Camron wrote:
HANDLE fptr;
bool bResult;
DWORD nBytesToRead = 20;
But here are the problems...
LPVOID inBuffer;
LPDWORD nBytesRead = 0;
These should be similar to the following:
<br />
UCHAR inBuffer[10000];
DWORD nBytesRead = 0;
Now with those changes, there is one more step before you can read...
fptr is a handle to a file - you haven't opened a file yet!
Now your attempt to read would become:
bResult = ReadFile(fptr, inBuffer, nBytesToRead, &nBytesRead, NULL);
After you read, you can close the file.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
<kmedcalf@ev1.net>
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Hello. I'm reading and excel (.xls) file using ODBC. For the most part it's working well, except I have a few columns that aren't being read accurately. The problem columns have data that can be either an int, text, or range such as int-int (ie. 12-16). The columns are specified as a general number format, although I have tried to change them to text.
The problem is that the results from the query are not reading all the data formats. So in a columns described above, it may only read int values, but not the range value. When it queries a cell with the range data the result is empty.
It seems that whatever type of value is first in the column defines which data type will be able to be read from the column. So if the first value in the column in a range (12-15), then only ranges will be accurately read, while int's will not.
Is this a probem with the database being setup incorrectly? Or is there a way to read the data regardless? as a string say?
Any thoughts on how I can fix this problem would be greatly appreciated.
Thanks.
|
|
|
|
|
The problem is in the logic used by the Excel ODBC driver. It treats the spreadsheet as if its rows and columns were rows and columns in a relational database table. As part of this, it assigns a datatype to each column. The problem is, a spreadsheet column may contain mixed datatypes. The ODBC driver makes a best guess at the datatype, based on the first couple of rows of data. Unfortunately, values for any cells that can't be expressed as this datatype instead appear as NULL.
Check out MSDN Knowledge Base Q257819 ("How To Use ADO with Excel Data from Visual Basic or VB"), particularly the section entitled "A Caution about Mixed Data Types".
|
|
|
|
|
does ::GetMetaFile() open the file once its called. what function do i call to close the metafile. Because once i try to open the file later, it gives me a sharing violation error.
thanks
|
|
|
|
|
GetMetaFile() has been superseded by GetEnhMetaFile() . When the handle is no longer needed, call DeleteEnhMetaFile() .
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I have been looking for a utility that would go thru my VC++ MFC project code and delete all unused files. My best guess is I need some kind of reverse compiler.
I have never done any compiler work (build a compiler) and have no clue where to start.
Any ideas?
Thanks for reading
Vaclav
|
|
|
|
|
Delete unused FILES ?
You can parse the DSP files, and if the file is not in it, then it is not used in the project.
Did you perhaps mean unused functions ?
|
|
|
|
|
Hi All,
I'm working on my first project in VS 2003 (coming from 6.0), and have run into a snag while creating a simple dialog. The problem is this. I am building a CAD application with MFC, and needed a dialog to manage the creation of one of the primitives. Simple enough.. I placed 2 radio buttons on the form (along with other controls), and then began assigning variables to the controls. The problem arose when the class wizard would not display any of the control ID's for the radio buttons. So, I tried to add the variable relations in by using DDX_Radio(). The program would give me a runtime error at that point that I couldn't track down. After troubleshooting for about an hour, I decided to place a CComboBox in instead since I could essentially track/manage the variable just as easily. After assigning a variable to the combo box, I went to fill it using AddString in the OnInitDialog() function. The problem is that the combobox doesn't drop. I can't see a way to manipulate it in the resource editor, and this has consumed and insane amount of time for such a simple task. I've never had a problem with this in VS 6.0, and it's a bit confusing.
Here's the code in my InitDialog (m_typeBox is the CComboBox control):
<br />
BOOL CTerminalPrompt::OnInitDialog()<br />
{<br />
CDialog::OnInitDialog();<br />
<br />
m_Elements = 1;<br />
m_typeBox.AddString("testing");<br />
m_typeBox.AddString("testing2");<br />
this->UpdateData(FALSE);<br />
<br />
return TRUE;
}<br />
Does anyone have any suggestions? Am I missing something?
Thanks, your help is a GREATLY appreciated
|
|
|
|
|
One thing off the top of my head. Make sure that the combobox is big enough to display the dropdown. It may be showing the dropdown but the control isn't big enough for you to see it. There appears to be two sizes for the combo. One size is what you see and the other is with the dropdown. At least, that's how I look at it.
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.
|
|
|
|
|
I can see the values in the editbox portion of the combo when I cycle through the mouse wheel, but the dropdown doesn't show up. I can't find a method to change the dropdown size, and it's not in the properties dialog.
|
|
|
|
|
Ahh, found in another recently posted thread.. I needed to click the 'down button' in the resource editor, and then it will allow me to resize the display rect, but only after clicking on the down button. Weird. I don't remember that . Oh well, thanks for your help Anon
|
|
|
|
|
That's the thing. That one bit me a time or two.
You're welcome.
|
|
|
|
|
I am creating a little console application in C++. The application is suppose to opens an html page using ShellExecute() wait for the html page to be closed and start a setup program using CreateProcess(). The problem I have is that both the html page the setup program start at the same time. I need the setup program to wait for the html page to be closed. I used WaitForSingleObject(), but it is not working. Any help would be appreciated, thanks. My code kinda looks like this:
Handle handle;
ShellExecute(handle, "open", filePath, ...);
if(WaitForSingleObject(handle, INFINITE)
{
CreateProcess(NULL, path, ...);
}
|
|
|
|
|
Well...
The first argument to ShellExecute, if I am not mistaken, is a WINDOW handle.
So, you can not wait on window handles with WaitForSingleObject.
Secondly, WaitForSingleObject will RETURN a value, like WAIT_FAILED if you pass it crap, which you have done. You should check the return value against WAIT_OBJECT_0 to imply success.
You should probably try to figure out which program is associated with the HTML file you are opening, and CreateProcess on it as well with appropriate command line arguments. You will get back a process handle as a successful result of the CreateProcess in the PROCESS_INFORMATION, and you CAN wait for this handle to be signaled to indicate the application has ended.
As an alternative, you might want to try getting ShellExecuteEx to work. It at least MIGHT return a process handle you can wait upon. Read its notes very carefully, however.
|
|
|
|
|
Thanks for suggesting that I use ShellExecuteEx. It gave me the handle that I needed to pass into WaitForSingleObject before calling CreateProcess.
|
|
|
|
|
Using Visual Studio 6.0, C/C++
=== Question 1
I am using the Workspace | ResourceView | Version
to input my current version info.
How do I read that info from within my code, so
that I can display it to the User on their demand?
=== Question 2
I am writing a Dialog-Based program. Is there any way to
show the User the About Box?
Many thanks,
Robert
|
|
|
|
|
Check out VerQueryValue() and GetFileVersionInfo() .
Robert Palma Jr. wrote:
I am writing a Dialog-Based program. Is there any way to
show the User the About Box?
Yes. If you used AppWizard, it was one of the choices.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Thank-you David, I am working on it.
Sounds like I have to read the version
info FROM the file on the HD, rather than
being able to read it from the image that
is currently in memory.
Thanks again,
Robert
|
|
|
|
|
I am not sure about your statement.
If you have the module handle (an image in memory), I think you can load the version resource from that as well, meaning you CAN get the version information from an image in memory.
I have not done this before, but this is what I would try to do:
For an image in memory, you can try FindResource -> LoadResource -> LockResource -> Use pointer in call to VerQueryValue -> FreeResource .
I think you can use SizeofResource if you need total size of resource information (in lieu of GetFileVersionInfoSize ).
You are using FindResource, LoadResource, and LockResource instead of GetFileVersionInfo .
FreeResource is called when you are done so that the memory is freed.
|
|
|
|
|
Here's the problem...
There are two DLLs, one is storing data and the other needs access to the same data. The data is not a fixed size - right now I'm adding objects to a vector to keep track of it. The DLL with the data is called by an application, not the other DLL that needs the data.
Using a shared data section -
#pragma data_seg(".shared")<br />
vector<SignalGroup> theVector; <br />
#pragma data_seg()
and using the linking command /SECTION:.shared,S
- doesn't work, I'm guessing because of the variable size of the vector.
Is memory-mapping the right route to take here? The size of the data block has to be specified with that as well I believe...
Thanks for any help.
|
|
|
|
|
I believe that creating a shared memory segment using Memory Mapped files is one of the better ways of sharing data between processes. You have to be careful about the size though, because that kind of shared area uses the paging file (IIRC).
Watch out for syncronizing access to the area, if you need to add and remove items from it.
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!)
|
|
|
|
|
Hello!
Im trying to convert an HBITMAP from a third party image class.. so that i can draw the image in a CView.. I have initialized all properties already except the bmiColors of the BITMAPINFO*. How do you initialize this, lets say for example i have 256 colors and 16 bits in the image? do i use RGB values or realized palettes?
having a hard time with this one?
tnx in advance.
maverick
|
|
|
|
|
16-bit image = no palette
256 colors implies an 8-bit image
the palette lives between the end of the BITMAPINFOHEADER and the start of the pixel data. you can find its size by calculating (1 << bmih.biBitDepth) * sizeof(RGBQUAD) .
a little pointer arithmetic will get you to the start of the palette: (address of the BITMAPINFOHEADER + sizeof(BITMAPINFOHEADER))
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|