|
Here is the code
char strPasswd[8] = "test123";
DWORD dlen = 8;
size_t t ;
long lSize;
size_t result;
BYTE* Newpasswd;
FILE *fp = fopen("c:\\test.bin", "wb+");
BYTE* encodedpasswd = EncodeString(strPasswd,&dlen);
t = fwrite((unsigned char*)encodedpasswd,1,sizeof((unsigned char*)encodedpasswd),fp);
fclose(fp);
fp = fopen("c:\\test.bin", "rb+");
fseek (fp , 0 , SEEK_END);
lSize = ftell (fp);
rewind (fp);
Newpasswd= (unsigned char*) malloc (sizeof(unsigned char)*lSize);
int i = fread(Newpasswd,1,sizeof(Newpasswd),fp);
char* tempPassword = DecodeString(testpasswd,&dlen);
Is writing is not done properly?
Regards,
|
|
|
|
|
I guess the problem is because you are using sizeof to calculate the lenght of your string. Sizeof will return the size (in bytes) of the pointer, not what it contains. So replace the first sizeof by a strlen (if the string is NULL terminated).
The others sizeof (in the malloc and in the fread) should be replaced by the size of the data that is retrieved from the file.
|
|
|
|
|
subramanyeswari wrote: I used fwrite and fread but it is not working.
(Un)fortunately It doesn't depend on fwrite and fread , my friend.
The following works for me (error checking left as exercise)
int main()
{
{
BYTE bValue[]={2,4,8};
int iLen = sizeof(bValue)/sizeof(bValue[0]);
FILE * fpo = fopen("foo.bin", "wb");
fwrite(&iLen, sizeof(iLen), 1,fpo);
fwrite(bValue, sizeof(bValue), 1, fpo);
fclose(fpo);
}
{
BYTE * bValue;
FILE * fpi = fopen("foo.bin", "rb");
int iLen;
fread(&iLen, sizeof(iLen), 1,fpi);
bValue = new BYTE[iLen];
fread(bValue, sizeof(BYTE), iLen, fpi);
fclose(fpi);
delete [] bValue;
}
return 0;
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi all,
I am working on a dialog box application...
i want to disable the cross button on top right corner on a particular condition and at other situations it may work.....
How can i do this?
thanks in advance
|
|
|
|
|
You can disable the button using the code shown below
BOOL bEnable = FALSE;
UINT menuf = bEnable ? (MF_BYCOMMAND) : (MF_BYCOMMAND | MF_GRAYED | MF_DISABLED);
CMenu* pSM = GetSystemMenu(FALSE);
if(pSM)
{
pSM->EnableMenuItem(SC_CLOSE, menuf);
}
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Hello,
I have an application which works fine .
I have now made DLL of the classes which I use.In one of the classes
it has a statement which calls the ParentFrame and sets the menu.
GetParentFrame()->SetMenu(&FrameMenu);
But when I use DLL in my application I get an unhandled error where it seems that the Parent Frame is not found
What must be the problem?
When I debug he application with DLL the debug cursor does not enter inside the DLL's .cpp file .I want to enter the DLL code .What should be
done for that?
Pritha
|
|
|
|
|
Why did you repost your question 1 hour after the previous one ? Did is a forum, not a chat. People can still see your question and this won't make any difference to ask it again except for spamming the forum.
|
|
|
|
|
Hello,
Sorry to repost my question.
But I did that because of my network connection.I posted my first question and could not see it on the screen after refreshing the page.When I tried to post it again,it said The question was posted and I thought the question subject must have collided with my earlier question which I posted 15 days back.so I changed the subject and reposted.
This will not happen again.
Regards.
Pritha
|
|
|
|
|
No problem, I thought you did that on purpose because you didn't replies fast enough
|
|
|
|
|
Hi all
i am new in vc++ and i am going to develop a USB project.My project is first monitor the USB port then i set permission.Permission like read and wright,enable and disble like that.Any one give me tips..
Thx's in Advance..
|
|
|
|
|
|
|
error C2352: 'CWnd::UpdateData' : illegal call of non-static member function
I am calling void SearchDialog::OnSearchBtn() from a thread.Please advice
class SeachDialog
{
....
....
protected:
// Generated message map functions
//{{AFX_MSG(AssetSearchDialog)
static afx_msg void OnSearchBtn();
....
static UINT StartWorkingThread (LPVOID param);
....
typedef struct THREADSTRUCT //structure for passing to the controlling function
{
SearchDialog* _this;
} THREADSTRUCT;
.....
....
}
UINT SearchDialog::StartWorkingThread (LPVOID param)
{
THREADSTRUCT* ts = (THREADSTRUCT*)param;
ts->_this->OnSearchBtn();
...
...
}
void SearchDialog::OnSearchBtn()
{
UpdateData(TRUE); // updates selection attributes
...
..
}
|
|
|
|
|
Hello,
I have an application which works fine .
I have now made DLL of the classes which I use.In one of the classes
it has a statement which calls the ParentFrame and sets the menu.
GetParentFrame()->SetMenu(&FrameMenu);
But when I use DLL in my application I get an unhandled error where it seems that the Parent Frame is not found
What must be the problem?
When I debug he application with DLL the debug cursor does not enter inside the DLL's .cpp file .I want to enter the DLL code .What should be
done for that?
Pritha
|
|
|
|
|
To debug your DLL, Set DLL project as active and under Project->Settings->Executable for Debug session browse the exe which is using your DLL.
|
|
|
|
|
Hello,
Thanks
But I aam using 2 DLLs and How should I debug starting from my client project?
Pritha
|
|
|
|
|
prithaa wrote: But I aam using 2 DLLs and How should I debug starting from my client project?
Set your dll project as the startup/active project. So when you press F5 you get a dialog prompting you to enter an exe name which will be hosting or using this dll, here browse and select the main exe which runs using this dll.
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
MFC has issues with multiple threads and possibly also with dlls. In this case GetParentFrame() is the culprit as it makes an internal call to CWnd::FromHandle which looks like this:
CWnd* PASCAL CWnd::FromHandle(HWND hWnd)
{
CHandleMap* pMap = afxMapHWND(TRUE);
ASSERT(pMap != NULL);
CWnd* pWnd = (CWnd*)pMap->FromHandle(hWnd);
#ifndef _AFX_NO_OCC_SUPPORT
pWnd->AttachControlSite(pMap);
#endif
ASSERT(pWnd == NULL || pWnd->m_hWnd == hWnd);
return pWnd;
}
The afxMapHWND func is probably trying to use global structures that aren't visible from the dll.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
hello,
thanks for the reply.
So I should not use the GetParentFrame() function.And what care should be taken regarding functions that go into the DLLs
Pritha
|
|
|
|
|
Can you avoid using MFC functions from the dll? Here you could use ::GetParent(m_hWnd) instead of GetParentFrame(), but it would give you a HWND, not CFrameWnd. If you can use only raw winapi calls it should be OK.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
If you use MFC with DLLs properly, you won't have a problem.
Everything you need to know can be found here:
Kinds of DLLs[^]
Read carefully
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hey guys,
I'd really appreciate any help you have to offer on this doozy of a problem:
I have a simulation process that I animate to screen using OnDraw() and CMemDC. I use a Timer with an Invalidate() call to call the OnDraw() funstion. In the OnDraw function the simulation is told to progress X number of steps - X being variable because it's important the user can speed the simulation up (real-time is waaaay too slow).
So here's the rub: if the timer is set to, say 50 ms (ie 20 frames per second - a reasonably slow animation rate) and the user requests say 5 simulation steps (each step representing say 100 ms of the real world), then the simulation process takes longer to exectue than 50 ms and we end up backing the message queue up so that the application fails to respond for quite some time.
I tried to do it by keeping a single simulation step per OnDraw call, and reduce the Timer interval, but with the resolution of the system clock this is limited to about 10 ms on my PC, so I only get about 10 x real world speed - still not enough.
I think the solution is to have the simulation and the animation operating seperately, with the animation *only* being called every 50 ms, but I don't know how to interrupt the running simulation. Plus, running the simulation at full speed means the program is not-reponsive and even further, if I could animate this, full speed may be too fast for the user - they need to be able to control the *Time Warp*.
I hope I've made this clear - apologies if not. I think this must be a common enough problem but I can't find anything on it really. If you've any suggestions I'd love to hear them!
Thanks in advance
|
|
|
|
|
Hi,
I have two inputs to offer you:
1.
timing behavior is the subject of my timers article; although it deals with .NET timer classes
the observations would be valid in C/C++/MFC environments too.
2.
I would never interrupt an ongoing simulation, it sounds like a waste of cycles already spent.
Instead I would make sure the increment of simulated time is sufficient for the simulator to stay
ahead of the requirements; one way of doing that would be to entirely skip simulations that are
in the queue but could not possibly get done in time. I hope I made myself clear on this.
|
|
|
|
|
Luc,
Thanks for your help. Your timer article is certainly valid - thanks. Your point about not interrupting the simulation is taken - in any case it would be very hard to code. So that's a given - a SimStep gets completed!
I've carried on searching and think I've got a close match - the game loop. For example using OnIdle() or other such functions. I found a good article here (through CP again ). My problem is the same as the problem he discusses with one important exception - my simulation step is variable (trust me on this!) and usually takes longer than an Invalidate(). So the game loop is close but not ideal.
I'll keep reading
|
|
|
|
|
Hi again,
I have been reading the article you referred to, and I liked it very much (except for the white-
on-black layout). Of course my preference is with "Constant Game Speed independent of Variable FPS",
which if I understood you correctly, for you would be ""Constant Game Speed with adaptable constant
speed, independent of Variable FPS"
I have one comment: the remark that more but smaller steps may yield larger overall errors is
correct when things are implemented like that, just accumulating numbers that are inaccurate to
begin with, but it doesn't have to be done that way.
It reminds me of (a lot of theory regarding) automatic numeric integration, as is used both
in mathematics in general, and in electronics; circuit simulators (such as SPICE) that handle say a
resistor-capacitor integrator really don't do just a sequence of predict-and-accumulate steps,
there are better ways to predict what in this simple case basically is an exponential curve without
spending lots of iterations and small time steps; I do recall the principles but not the official
name right now; I do remember it is very much like a regular feedback mechanism in control theory,
whereby the inherent accumulation error or prediction error corrects itself away to a very
large extent. It might be worth looking into.
[ADDED]Seems "backward integration rule" is something Google knows about... [/ADDED]
|
|
|
|