|
I have found that using dynamic memory allocation is always preferable, because some of the Microsoft MFC code contains the line:
delete this;
This will cause an exception if such a window or control is declared on the stack, and from experience it can be very frustrating to locate the source of the failure when it happens.
|
|
|
|
|
do u believe Microsoft people are so foolish to do that?:->
Can u say an example...?
They might have wrote such a code because they will be that much sure that the "Object" is created in the heap.
nave
|
|
|
|
|
Using the heap (i.e. new) instead of the stack can cause all sorts of performance problems due to the memory manager. However, large objects (for example, something over 20k) might cause problems if allocated on the stack.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Generally you should declare objects on the stack unless you need to declare them on the heap. If you do declare them on the heap consider using a smart pointer.
Kevin
|
|
|
|
|
Thanks...
---
Hakuna-Matada
It means no worries for the rest of your days...
It's our problem free, Philosophy
<marquee behavior="alternate" scrollamount="5" scrolldelay="50">
|
|
|
|
|
|
Hi,I got this error when i rebuild my coding.Im working with this coding,when i just run this coding it does not show this error,finally when i rebuild this to get EXE i got this error..
Linking...
nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in Communciation.obj
.\Debug/CS3OperatorStation.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
I used unsigned int only in one class in TagInfo.cpp not in communication.cpp..I am using unsigned int in these four lines only..
unsigned int CTagAlrmLgt::GetColor(int iNo)
unsigned int nTopColor;
unsigned int nBotColor;
unsigned int GetColor(int);
Please help me out to find the error..
Anu
|
|
|
|
|
have u over loaded the new operator?
nave
|
|
|
|
|
|
Hello,
I have a application SDI that use also other dialog modless. I would like use a vitual key (like F4) to do something. It works only when the main appliccation have a focus but not when a other dialog from the same application. What can I try to make that possible.
Thank you !! I have tryed and it works
-- modified at 2:46 Monday 21st August, 2006
AutreChien
|
|
|
|
|
u must map the WM_KEYDOWN in the PreTranslateMessage() function of app class like this
BOOL CSdiApp::PreTranslateMessage(MSG* pMsg) <br />
{<br />
if( WM_KEYDOWN == pMsg->message )<br />
{<br />
if( pMsg->wParam== VK_F4)<br />
{<br />
AfxMessageBox( _T("f4 pressed"));<br />
}<br />
<br />
}<br />
return CWinApp::PreTranslateMessage(pMsg);<br />
}
nave
|
|
|
|
|
|
I am struggling with find() of map for last 15 day, my target is reading EVENTLOGRECORD from all machine at a time (with help of multithread ) and doing some processes on the information and writing to a separate file for each machine. It is working fine for a machine at a time. if I I read more than one machine for > 4 hours data from the machine, the map.find() giving exception . it is not frequently happening
What will be the error ?
My code
map<string ,cevent="" *=""> m_eventlist;
map<string,cevent *="">::iterator m_iter;
m_useriter=m_userlist.find(newkey); -
CEvent is a user defined object
thanks
|
|
|
|
|
I would guess this is because you're accessing the map (and likely other things) from multiple threads without synchronization. Multithreaded programming is hard.
Steve
|
|
|
|
|
Dear Sir,
I am using Roger Allen Preview Extension to do PrintPreview.
I have a file that I need to Preview all records and i make a loop on OnpreparePrinting to do So, I see only the last page, all previous I don't see it.
My problem perhaps is that I did n't yet use Doc/View printing, I do only printing with non Doc/View facility.
Who can help me ?
|
|
|
|
|
hi,
Here i have one probleme regarding VC++,if anyone know the solution plz give me the suggetions.the problem is that i have written a programe to diaplay the Rectangle.Now if i want to change the size of the Rectangle and move it Position of the Rectangle through mouse what i have to do?
bulusu ramanand
-- modified at 0:46 Saturday 19th August, 2006
|
|
|
|
|
|
I have 3 projects in workspace.I use VC 6.0.
project DipApi is a win32 static Library
They are all functions.
project CDib is MFC extension DLL,and use DibApi.lib
It will export a class.These is the header file Dib.h of the class,below
#include "..\DibApi\DIBAPI.H"
class AFX_EXT_CLASS CDib : public CObject
{
DECLARE_SERIAL(CDib) //serialization
......
export dll is ok.
CDibEx also is a MFC extension DLL project,use DibApi.lib too,and the upper class.
It will export a class too.These is the header file DibEx.h of the class,below
#include "..\dibapi\dibapi.h"
#include "..\cdib\Dib.h"
//This is the upper header file.I do not know whether to change it.
#define EFFECT_SCANDOWN 1
#define EFFECT_SCANUP 2
#define EFFECT_SCANRIGHT 3
class AFX_EXT_CLASS CDibEx : public CDib
{
DECLARE_SERIAL(CDibEx) //serialization
... ...
but ,when building,VC show:
Creating library Debug/CDibEx.lib and object Debug/CDibEx.exp
DibEx.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass
CDib::classCDib" (?classCDib@CDib@@2UCRuntimeClass@@A)
Debug/CDibEx.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Look for AFX_EXT_CLASS in MSDN.In Export and Import Using AFX_EXT_CLASS,it has
"For example, the DECLARE_DYNAMIC macro is defined as follows when building an extension
DLL:
#define DECLARE_DYNAMIC(class_name) \
protected: \
static CRuntimeClass* PASCAL _GetBaseClass(); \
public: \
static AFX_DATA CRuntimeClass class##class_name; \
virtual CRuntimeClass* GetRuntimeClass() const; \
The line that begins with static AFX_DATA is declaring a static object inside of your
class. To export this class correctly and access the run-time information from a client
executable, you must export this static object. Because the static object is declared with
the modifier AFX_DATA, you only need to define AFX_DATA to be __declspec(dllexport) when
building your DLL and define it as __declspec(dllimport) when building your client
executable. Because AFX_EXT_CLASS is already defined in this way, you just need to
redefine AFX_DATA to be the same as AFX_EXT_CLASS around your class definition.
For example:
#undef AFX_DATA
#define AFX_DATA AFX_EXT_CLASS
class CExampleView : public CView
{
DECLARE_DYNAMIC()
// ... class definition ...
};
#undef AFX_DATA
#define AFX_DATA
"
I am sorry for knowing unclearly,so I did know whether it relate to my problem.
Actually,I want to make two class to dlls respectively.
But I don't know where I was wrong.Please tell me ,thanks a lot!
begtostudy
|
|
|
|
|
http://msdn.microsoft.com/library/en-us/vccore/html/_core_Mutual_Imports.asp
I solved by myself!
|
|
|
|
|
Hello,
I'm don't receive any packet with winsock program.
My code is:
SOCKET RecvSocket,SendSocket;
int ReceiverAddrSize = sizeof(RecvAddr);
RecvSocket = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
SendAddr.sin_family = AF_INET;
SendAddr.sin_port = htons(Port);
SendAddr.sin_addr.s_addr = htonl(INADDR_ANY);
length = recvfrom(RecvSocket, SendBuf, BufLen, 0, (SOCKADDR *) &RecvAddr, &ReceiverAddrSize);
if (length == -1) {
printf("ERRO - RECVFROM\n");
exit(1);
}
Can you help me?
thanks
|
|
|
|
|
I have a multithreaded dll which reads and writes to files. For debugging purposes I would like to switch between multithreaded and singlethreaded from my main app. So I placed the following in the dll code
#ifdef _DLLNOUSETHREAD
LoadMonthThread();
#else
_handle = (HANDLE)_beginthreadex(NULL,0,LoadMonth,this,0,&_threadID);
if (!_handle)
ShowError();
#endif
I was hoping to simple be able to define _DLLNOUSETHREAD in the main exe to be able to switch, but it isn't working like that. The dll always fires a thread. What did I do wrong here?
|
|
|
|
|
are you rebuilding the DLL when you change the #define ?
|
|
|
|
|
What (the other) Chris is trying to say is that preprocessor directives like #ifdef modify how the code is compiled, they do not exist in the final binary (exe or dll).
So, in your example, when you compile the dll _either_ the LoadMonthThread() _or_ the _handle = ... code will be compiled into the dll, not both.
If you replace the: #ifdef, #else, #endif, with: if( SomeDllVar ) {}, else {} then your main app could change SomeDllVar.
... however, you state this is to aid in debugging, i have never seen anyone do this.
Either you need the MT, in which case suck it up (in a friendly sort of way ) and debug the MT dll, or it doesn't need to be MT.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
hello,
i want to extract message number 1800(for example) from xpsp2res.dll (c:\windows\system32\)
the problem is in findsource ;
this is my code
HANDLE handle = NULL;
HRSRC hrsrc;
HRSRC hResLoad;
DWORD dwLongBuff;
char Buffer[MAX_BUFFER_SIZE];
handle=LoadLibrary("C:\\windows\\System32\\xpsp2res.dll");
if (handle==NULL) printf("failure to load"); else printf ("loading ok\n");
hrsrc=FindResource((HMODULE)handle,MAKEINTRESOURCE(1800),RT_MESSAGETABLE);
if (hrsrc==NULL) printf("failure to load2"); else printf ("loading ok2\n");
|
|
|
|
|
I use VC++ 2005 and created a Win32 console application. I got the error messages:
Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup MSVCRTD.lib
Error 2 fatal error LNK1120: 1 unresolved externals C:\C++ Projects\ImageStore\Debug\ImageStore.exe 1
Here is the code. Thanks in advance!
//Imagestore.cpp
#using <system.dll>
#using <system.data.dll>
using namespace System;
using namespace System::Collections::Generic;
using namespace System::Text;
using namespace System::Data;
using namespace System::Data::SqlClient;
using namespace System::IO;
namespace ImageStore
{
private ref class Class1
{
public:
static int Main(array<system::string^> ^args)
{
int errorCode = 0;
Class1 ^oMain = gcnew Class1();
System::String ^sConStr = "Data Source=YANG;Initial Catalog=NorthWind;Integrated Security = True";
int iUserID = Convert::ToInt32(args[0]);
System::String ^sRequestTime = args[1];
System::String ^sImageType = args[2];
System::String ^sFilePath = args[3];
FileInfo ^fi = gcnew FileInfo(sFilePath);
FileStream ^oImg;
BinaryReader ^oBinaryReader;
array<system::byte> ^oImgByteArray;
if (fi->Exists)
{
try
{
oImg = gcnew FileStream(sFilePath, FileMode::Open, FileAccess::Read);
oBinaryReader = gcnew BinaryReader(oImg);
oImgByteArray = oBinaryReader->ReadBytes(safe_cast<int>(oImg->Length));
oBinaryReader->Close();
oImg->Close();
oMain->SaveImage(sConStr, iUserID, sRequestTime, sImageType, oImgByteArray);
}
catch (Exception ^e)
{
Console::WriteLine(e->Message);
}
}
else
{
errorCode = 2;
}
return errorCode;
}
void SaveImage(System::String ^sConnectionString, int iUserID, System::String ^sRequestTime, System::String ^sImageType, array<system::byte> ^oImage)
{
SqlConnection ^oConn = gcnew SqlConnection();
try
{
oConn->ConnectionString = sConnectionString;
oConn->Open();
SqlCommand ^oCmd = gcnew SqlCommand("dbo.qp_SaveImage", oConn);
oCmd->CommandType = CommandType::StoredProcedure;
oCmd->Parameters->Add(gcnew SqlParameter("@iUserID", SqlDbType::Int));
oCmd->Parameters->Add(gcnew SqlParameter("@vcRequestTime", SqlDbType::VarChar, 100));
oCmd->Parameters->Add(gcnew SqlParameter("@vcImageType", SqlDbType::VarChar, 50));
oCmd->Parameters->Add(gcnew SqlParameter("@imImageFile", SqlDbType::Image, 2147483647));
oCmd->Parameters["@iUserID"]->Value = iUserID;
oCmd->Parameters["@vcRequestTime"]->Value = sRequestTime;
oCmd->Parameters["@vcImageType"]->Value = sImageType;
oCmd->Parameters["@imImageFile"]->Value = oImage;
oCmd->ExecuteNonQuery();
}
catch (Exception ^e)
{
Console::WriteLine(e->Message);
}
finally
{
if (oConn->State == ConnectionState::Open)
{
oConn->Close();
}
}
}
};
}
-- modified at 13:02 Friday 18th August, 2006
|
|
|
|