|
Hi, Anthony, thank you for reply. i m trying to use the one u suggest. but the code is hard to understand.
in case, i really dun know how the parameter "myPort" which in etAddressLptPort GetAddressLptPortInTheRegistry GetAddressLptPortInTheMemory
hv been used.
u have any idear abt it.
btw i m trying to get that book to c how. thank u very much!
|
|
|
|
|
I have a question for any of the experts out there but first here is some code...
I wrote the following code in C# for reading absolutely any file type. It does work perfectly for any file type and the method or style is called a binary file reader....
byte[] buffer = new Byte[SizeBuff];
int bytesRead = 0;
int ByteCounter = 0;
inputStream = File.OpenRead(@InputFile.Text);
while ((bytesRead = inputStream.Read(buffer,0,SizeBuff)) > 0)
{
ByteCounter = ByteCounter + bytesRead;
}
int TotalBytes = ByteCounter;
byte[] ModifyThisFIle = new Byte[TotalBytes];
int KiloByteCounter = 0;
inputStream.Close();
inputStream = File.OpenRead(@InputFile.Text);
while ((bytesRead = inputStream.Read(buffer,0,SizeBuff)) > 0)
{
for (int a = 0; a < bytesRead; a++)
{
ModifyThisFIle[a + (KiloByteCounter * 1024)] = buffer[a];
}
KiloByteCounter = KiloByteCounter + 1;
}
NOT TXT file types and NOT the simple ifstream statements....
What is the simular or identical method for reading each character of a file IN VC++??? "What is included within and including the while loop statements to read" in VC++ for binary files like JPG, HLP, PDF, etc???
Thanks,
demasoni.com
Elite
|
|
|
|
|
You could try the C api.
FILE *fSrc;
if ( (fSrc = fopen(".\\yourfile.bin", "rb")) == NULL)
assert(NULL);
int nLoop = yourGetFileSize(".\\yourfile.bin");
UCHAR *pBuffer = new UCHAR[nLoop +1];
int p = 0;
while (nLoop)
{
pBuffer[p] = (UCHAR)fgetc(fSrc);;
nLoop--;
p++;
}
fclose(fSrc);
delete [] pBuffer;
This will read byte by byte to the UCHAR buffer.
I am sure there are some STL based functions which could do the same.
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
Thanks very much,
Interesting structure. I am not familiar with the term , "rb" that is located within the if loop but I assume with your above comment it means Reading Binary.
I also noticed something else that is a little bit different are the 2 semicolons ;; located within the while loop. That is new to me as well.
Please Quote me on this but I assume the pBuffer array is where each char is placed then it is deleted with the delete statement after you finnish what ever it is you need to do before you delete the array???
Also I noticed that you used UCHAR, I assume you could use BYTE as well???
Are there any special include files I need???
demasoni.com
Elite
|
|
|
|
|
I also noticed something else that is a little bit different are the 2 semicolons ;; located within the while loop. That is new to me as well.
that is typo.
Please Quote me on this but I assume the pBuffer array is where each char is placed then it is deleted with the delete statement after you finnish what ever it is you need to do before you delete the array???
yes
Also I noticed that you used UCHAR, I assume you could use BYTE as well???
Yes, UCHAR is a unsigned char which has the range of 0 to 255, thus equivalent to BYTE. Reason to use UCHAR is that data type name is self explanatory the reason of using the type, just to save a few comments on your code.
You can not use _int8 or char here because this data type are from –128 to 127.
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
.
Thanks for your help Anthony_Yio,
Enjoy the weekend.
demasoni.com
Elite
|
|
|
|
|
repost....; mad:
TOXCCT >>> GEII power
|
|
|
|
|
Why are you reading the file twice and throwing away the bytes read in the first pass? Here's a function to read all the bytes of a file in one pass to a C++ std::vector .
#include <fstream>
#include <vector>
#include <string>
using namespace std;
const int SizeBuff=1024;
typedef unsigned char BYTE;
void readFile(const string& inputFile, vector<BYTE>& buffer)
{
ifstream inputStream;
vector<BYTE> tmpBuf(SizeBuff);
streamsize bytesRead;
inputStream.open(inputFile.c_str(), ios::in|ios::binary);
while(inputStream) {
inputStream.read(reinterpret_cast<char*>(&tmpBuf[0]), SizeBuff);
bytesRead=inputStream.gcount();
if(bytesRead > 0) {
buffer.insert(buffer.end(), tmpBuf.begin(),
tmpBuf.begin() + bytesRead);
}
}
inputStream.close();
}
|
|
|
|
|
markkuk said...
Why are you reading the file twice and throwing away the bytes read in the first pass? Here's a function to read all the bytes of a file in one pass to a C++ std::vector.
That was when I was new to C#. I was making the first pass to get the actual number bytes in the file so I could use it to fill dynamic arrays with each character. I did not know at that time what method or call was used to get the size. Yes, I knew before I placed the code on this thread that it is a waste of time to read a file twice. I do know C# now, and I know console C++. Just a couple of days ago I have migrated to VC++MFC which I am still a little bit new at, your help is greatly appreciated.
Thanks markkuk,
Interesting function you have.
Vector is a STL container. You are passing both the "file_path_and_name" and the vector named buffer by reference so it is a void function. You also used a typedef.
So within the main program you could...
vector<BYTE> BufferNumberOne;
readFile("C:\files\picture1.jpg", BufferNumberOne);
for (int a = 0; a < BufferNumberOne.size(); a++)
{
BufferNumberOne[a];
//do stuff like fill array, modify chars, or etc.
}
or would you...
String some_file = "C:\files\picture1.jpg";
vector<BYTE> BufferNumberOne;
readFile(some_file, BufferNumberOne);
for (int a = 0; a < BufferNumberOne.size(); a++)
{
BufferNumberOne[a];
//do stuff like fill array, modify chars, or etc.
}
Please quote me if I am wrong on any of the above statements.
In past C++ courses we used statement like while(!EOF) but EOF is char 26, ^Z and it exists many times within jpg or other such file types that use any or all of the 256 different characters. Not many C++ text books discuss methods in any detail at all on how to read files of types other than txt.
Thanks Much markkuk,
demasoni.com
Elite
|
|
|
|
|
You can call the function both ways, just remember that the standard string type is string , not String . Some error checks should be added to the function before using it in a "real" program.
The constant EOF in C and C++ code isn't the ASCII EOF character, it's an integer value different from any character and can be used with any types of file.
|
|
|
|
|
Thanks for the info,
Your help will save me quite a bit of time. Enjoy the holiday.
jjs
Elite
|
|
|
|
|
Hi.
I want to add a licensing support to an existing project.
I did this:
Added this two lines to the control's immplementation file:
static const TCHAR BASED_CODE _szLicFileName[] =
_T("License.lic");
static const WCHAR BASED_CODE _szLicString[] =
L"Copyright (c) 1995 ";
then these functions:
BOOL CLicenseCtrl::CLicenseCtrlFactory::VerifyUserLicense()
{
return AfxVerifyLicFile(AfxGetInstanceHandle(),
_szLicFileName, _szLicString);
}
BOOL CLicenseCtrl::CLicenseCtrlFactory::GetLicenseKey(DWORD dwReserved,
BSTR FAR* pbstrKey)
{
if (pbstrKey == NULL)
return FALSE;
*pbstrKey = SysAllocString(_szLicString);
return (*pbstrKey != NULL);
}
but it does not work. I figured out that the license keyword needs to be added to the .odl file, and also a license key created.
Anybody that can direct me to a good site explaining this? Thanks.
.
|
|
|
|
|
How can you stop the Tab key acting as an Enter key during text entry into a Edit Box.
If I enter text into the Edit Box and press the Tab key, then the program acts as if the Enter key was actioned.
grahamfff
|
|
|
|
|
I think the tab key was overrided for switching between controls in CWnd.
You could use CTRL D to see the sequence of tab sequence.
My opinion will be override the OnKeyUp of your CWnd for VK_TAB.
But probably there are simpler way to do.
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
See Michael Dunn's C++ FAQ on this site. It outlines a good method.
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"
|
|
|
|
|
Could not see it on the FAQ list to quoted, could you specify a link please.
This apprears adifficult problem to solve!
|
|
|
|
|
|
Spoon....
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
Huh?
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 trying to create a program using the CreateProcessWithLogonW. I am working on a Windows 2000 Professional. The program compiles fine but when it tries to link it, it gives the following errors:
Linking...
CreateProcess.obj : error LNK2001: unresolved external symbol __imp__CreateProcessWithLogonW@44
Debug/CreateProcess.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Creating browse info file...
CreateProcess.exe - 2 error(s), 0 warning(s)
The code that I am trying to compile is as follows:
#define UNICODE
#define _WIN32_WINNT 0x0500
#define WINVER 0x0500
#include <windows.h>
#pragma comment(lib, "Advapi32")
int main(int argc, char* argv[])
{
STARTUPINFO si;
si.cb = sizeof(STARTUPINFO);
PROCESS_INFORMATION pi;
if (CreateProcessWithLogonW(L"UserName", L"Domain", L"password", LOGON_WITH_PROFILE, NULL, L"\"full file path\"", CREATE_DEFAULT_ERROR_MODE, NULL, L"\"current directory\"", (LPSTARTUPINFO)&si, (LPPROCESS_INFORMATION)&pi)) {
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
return 0;
}
|
|
|
|
|
smbecker wrote:
#pragma comment(lib, "Advapi32")
change to
#pragma comment(lib, "Advapi32.lib")
Rob Manderson
I'm working on a version for Visual Lisp++
|
|
|
|
|
I made the change and I am still getting the same linking error as before. Any other suggestions? Thanks
|
|
|
|
|
Hey all,
I got 2 questions.
1st one is how do you change the size of a CString? I have tired and I couldn't get it, here is what I have tried.
<br />
CFont font;<br />
font.CreatePointFont(480, "Arial", &dc);<br />
<br />
<br />
CString str("DEP");<br />
<br />
CSize size = dc.GetTextExtent(str);<br />
<br />
dc.DrawText(str, printArea, DT_NOPREFIX | DT_WORDBREAK);<br />
<br />
2nd question is how do you get a Veritcal Scroll Bar to work? I know how to add it to a Dialog, but can't get it to scroll.
Thanks for the help
|
|
|
|
|
Before a call to the device context functions, you need to select the graphics object(s) you need to work with; in your case, a CFont object. Write the following statements before and after a call to the DrawText(...) function respectively:
Before
CFont *pOldFont = dc.SelectObject(&font);
After
dc.SelectObject(pOldFont);
Gurmeet BTW, can Google help me search my lost pajamas?
My Articles: HTML Reader C++ Class Library, Numeric Edit Control
|
|
|
|
|
I am trying to access an Excel spreadheet in Visual C++ 6.0. I am using the XL5EN32.OLB library. However I keep getting errors, one of which is:
error C2440: 'type cast' : cannot convert from 'class Sheets' to 'class COleVariant'
I just wanted to be able to pull data out of a spreadsheet and use it in my program. There are problems with Ole. I thought you could define a sheet from the workbook object. However it does not allow me to do this. You have do get sheets from a workbook and a workbook from a file. But I can not do this, the return types don't match. I looked at MSDN article 179706
http://support.microsoft.com/default.aspx?scid=kb;EN-US;179706
It doesn't seem to work that way though. I don't know how they got the return types to match.
COleVariant fn;
CString f;
Application app;
Workbooks books;
Workbook book;
Range pRange;
Sheets sheets;
double Result;
COleVariant
covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
app.CreateDispatch("Excel.Application");
app.SetVisible(covTrue);
books.Open(fn, covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional);
sheets = book.Sheets(COleVariant((short)(1)));
|
|
|
|