|
Thank you for the information!
Hosam Aly Mahmoud
|
|
|
|
|
Thank you for your replies, your help and all your patience!
Hosam Aly Mahmoud
|
|
|
|
|
Hi,
I've written a program and when I run it for the first time it works, but when I want to run it for the second time, it crashes. Most of the time at a "delete [] ..." or at a "new char[...]". But when I debug it works fine.
The program uses a MySQL database (through MySQL++). Somewhere in the code is a "for()" part (it retrieves the records of a SQL-statement and does something with the values). When I debug it, it only goes one through the loop (retrieves one record), when I compile an optimized exe then it retrieves all the records.
I think this is very weird, does anybody knows the cause of the problem or has a sollution?
Thanks in advance
|
|
|
|
|
Sounds like an uninitialized variable somewhere.
- Mike
|
|
|
|
|
I see what you mean but how can something like this crash on "new ..."?
char* cNewString = NULL;
// cString is not empty
cNewString = new char[strlen(cString) + 1];
-Tom
|
|
|
|
|
Visual C++ is not perfect in reporting the cause of a crash and where the bug resides. One possible cause of delete [] is that the program passes the dynamically allocated array into a function that does not release the memory even after the function has returned.
Kuphryn
|
|
|
|
|
Probably a newbie question but I really want to ask, I have like hundreds of jpg's, gif's and icons need to be shared by multiple application, I heard we can encapsulate all of them into a dll and use that dll to export resource ID's when required by application, but how? Could someone please tell me:
1, what kind of dll I will need to create? Win32 dll? MFC dll? Or others?
2, How do I export resource ID's from a dll?
Thanks a lot.
|
|
|
|
|
putting hundreds of jpgs in a dll is a very bad idea, because it will waste your memory... you won't need them all the same time!
create a folder, put them in there, then create a new dll with 2 exported function: LoadJpg and FreeJpg!
LoadJpg allocates memory and loads the file from disk, FreeJpg frees the memory allocated by LoadJpg!
This is the best way!
Don't try it, just do it!
|
|
|
|
|
Yeah I thought so, but I was just doing some practice, thanks for the suggestion though...
Anyway, I think I have found out the solution already, I created a DLL and included images into that DLL as its resources, then in my executable I read images("resource blocks") from the DLL into my executable process's memory blocks when needed, then draw them on my executable's windows, tested and worked.
|
|
|
|
|
use a normal win32 dll and include the resources there!
then load this dll via LoadLibrary!
now, you can open a bitmap for example by calling LoadBitmap with hInstance of the loaded dll!
Don't try it, just do it!
|
|
|
|
|
I am trying to create an application that is capable of working with multiple document types, each having its own view. In the InitInstance() function I have done the following:
BOOL CTestApp::InitInstance()
{
... Other code
LoadStdProfileSettings(15); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(IDR_FIRSTTYPE,
RUNTIME_CLASS(CTypeOneDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CTypeOneView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
CMultiDocTemplate* pDocTemplateT;
pDocTemplateT = new CMultiDocTemplate(IDR_SECTYPE,
RUNTIME_CLASS(CTypeTwoDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CTypeTwoView));
if (!pDocTemplateT)
return FALSE;
AddDocTemplate(pDocTemplateT);
... Other code
I have all appropriate view and document classes in place for these doc templates and the project compiles without any problems. The first doc view is derived from CHTMLView and the second is derived from CRichEditView.
PROBLEM:
I create a new rich edit document, type some text into the view, and save it and then close the document. Then when I open the document I just saved, it appears that the document's contents had never been saved, or if they had, they certainly didn't open properly.
ALSO:
The messagebox that usually automatically pops up when you try to close a doc that has not been saved since its last modification fails to come up like it should.
I believe that these two problems are somehow related. Please help.
This has really got me stuck. Does anyone have any suggestions? Any leads to the problem would definitely be appreciated.
BNEACETP
|
|
|
|
|
|
Thanks for letting me know about the book.
I just ordered it earlier today.
BNEACETP
|
|
|
|
|
I was wondering if it were at all possible to derive a class template from another class template and keep the base class templates arguments abstract. I have looked around and cannot find the answer.
|
|
|
|
|
Mike Roode wrote:
I was wondering if it were at all possible to derive a class template from another class template
template<class T>
class Base
{
};
template<class T>
class Derived : public Base<T>
{
};
Is this what you meant? You can add any additional template parameters required in derived.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
That is what I was looking for. Thanks for the syntax Andrew.
|
|
|
|
|
Hi everyone. Again I have some questions, actually a problem with using the MFC class CRecordset. I have implemented a class which will manipulate a database (Oracle 9i). When I try to add a new employee (Employee is the object that carries the data) I get the following error:
---------------------------------------------------------------------------------------
Runtime error:
The application has requested the Runtime to terminate it in an unusual way.
I have this error only with the specific method. The other operations (update, select, delete on the same table work fine).
Does anyone know what is causing it?
bool Service::AddNew(Employee e){
long id;
EmployeeRecordset records(db);
//Begin transaction
db->BeginTrans();
//open the recordset only for adding records mode
try{
if ((records.Open(CRecordset::dynaset,NULL,CRecordset::appendOnly))!=0){
//if recordset is updateable add new record
if (records.CanAppend()){
//find the last YP_ID
records.MoveLast();
id = records.m_YP_ID + 1;
records.AddNew();
records.SetFieldNull( NULL );
//copy new values
//this where I copy the new values to the recordset
//here is where I have the error
if (records.Update()){
//end transaction
db->CommitTrans();
records.Close();
return (true);
}//end if
}//end if
}//end if
}//end of try
catch (CDBException cdbe){
db->Rollback();
records.Close();
return (false);
}//end of catch
catch (CMemoryException cme){
db->Rollback();
records.Close();
return (false);
}//end of catch
cout << "end of addnew" << endl;
db->Rollback();
records.Close();
return(false);
}//end of AddNew
|
|
|
|
|
I'm making a server that should be able to handle multiple connections at once. I use WSABUF, WSASend and WSAReceive in my code but when i try to compile i get the error that they are undefined, even though i am sure winsock 2 is included because i have explicitly included winsock2.h but also have defined _WIN32_WINNT as 0x400. So does anyone know why it is giving me the errors? do i need to include something else as well?
And another question, i am making a server that will be handling upto about a maximum of 200 clients. I've looked into some ways to do it and as i see it there are two ways: A simple multi-threaded server, or to use Input Output Completion Ports. I was told the latter was faster and more stable but i was wondering, where do u draw the line to go from a simple multi-threaded server to a IOCP server?
Many thanks in advance.
Kuniva
--------------------------------------------
|
|
|
|
|
Include ws2tcpip.h
I highly recommend IOCP for multiclient servers. There are several factors to consider when deciding on IOCP or multithreading such as OVERLAPPED and event driven I/O. One is connection. Given that 100 clients connect in within 1 sec, IOCP surpasses all other nonblocking I/O. Overall, the benefit of I/O is in the handling of thousands of clients with limited or any lag or loss of data.
Kuphryn
|
|
|
|
|
Cool, thanks!
Kuniva
--------------------------------------------
|
|
|
|
|
ack.. now i have another problem, it still seems to include winsock.h somehow because when i try to compile it gives me a lot of redefinition errors between winsock.h and WS2tcpip.h (like IP_TOS, IP_TTL etc).
Kuniva
--------------------------------------------
|
|
|
|
|
Include winsock2.
Kuphryn
|
|
|
|
|
Hi,
I'm writing an application that stores some temporary files on disk and deletes them on closing (there is no way around this). To be tidy, I want to tell the application to delete the files if the computer is restarted whilst it is running, and thus I have used MoveFileEx with MOVEFILE_DELAY_UNTIL_REBOOT for Win2000 etc, and the WinInit.ini file for Windows 9x.
When the program ends, it is easy to cancel the "DeleteFileOnReboot" function I am using for Win 9x, as all I have to do before amending WinInit.ini is check if it exists (if it doesn't I can just create it then delete it on closing), and if it does save its settings using GetPrivateProfileSection and then restore them when my app ends using WritePrivateProfileSection.
However, I have no idea how to cancel MoveFileEx for Win2000/NT/XP platforms, as this stores all the files to be deleted in the registry. (I am a relative novice, and have never played with the registry before in an application.)
MSDN gives the following info:
[quote]
The function stores the locations of the files to be renamed at restart in the following registry value:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations
This registry value is of type REG_MULTI_SZ. Each rename operation stores the following pair of NULL-terminated strings:
szDstFile\0\0
szSrcFile\0szDstFile\0\0
[/quote]
Unfortunately, I have no idea how to use this information... If anybody could tell me how I can cancel MoveFileEx after it has been called for files using the MOVEFILE_DELAY_UNTIL_REBOOT flag, I would be really grateful.
Many thanks,
KB
P.S. I am using the straight Windows API with *no* MFC.
|
|
|
|
|
IMO you're approaching the problem the wrong way. Instead of complicated logic involving INI files and cancelling API calls, just keep a list of the temp files you create. In your app's shutdown code, go thru the list and delete the files. You can handle WM_QUERYENDSESSION and WM_ENDSESSION to know when the computer is being shut down.
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
Thank you for your reply, much appreciated - this is really useful information. I didn't even know about these messages (my knowledge is fairly limited as I'm in the process of learning).
Unfortunately this isn't really a solution, though, from what I have read on MSDN. If a user hits the "power off" button or the "reboot" button on his (or her) PC, the WM_QUERYENDSESSION and WM_ENDSESSION messages won't get sent, meaning the files will be left on the harddrive. So unless I am totally wrong about this, I guess I am stuck with trying to find out how to delete the relevant MoveFileEx info from the registry...
Many thanks for any help,
Cheers,
KB
|
|
|
|