|
Hi,
I a bit confused to use OLE service for Crichedit
I use the SetOleCallBack to set the pointer ???
If yes
then What is GetIRichEditOle all about
thankx
|
|
|
|
|
Hi all,
1) Can we use free() function to free the memory allocated by "new" operator.
2) Can we "delete" operator to delete the memory allocared by malloc() function.
Thanks in advance
sAI
|
|
|
|
|
new and delete can be overloaded, so generally speaking, you can't do that.
|
|
|
|
|
You shouldn't. It may or may not work, depending on the implementation.
Steve
|
|
|
|
|
The short answer to both these questions is: No, never, ever, ever, ever mix calls to new/delete and malloc/free.
The long answer is that, unlike malloc and free, new and delete don't allocate and release memory, they create and destroy objects. If you try and free an object created by new the destructor for the object won't be called, if you malloc a block of memory the constructor for whatever type you assign the pointer to won't be called.
Cheers,
Ash
PS: In case I haven't said it strongly enough, don't do it. Really. Future generations of maintenance programmers will curse your name if you try it.
|
|
|
|
|
These methods are to be used in pairs and you should not mix them.
If you allocate memory with malloc then you need to free it with free . The same goes for new and delete .
C Memory Functions
malloc : Allocates an uninitialized block of memory, given the number of bytes.
calloc : Allocates a zero initialized block of memory, given the number of elements and the size of the element.
free : Deletes the memory allocated by malloc or calloc .
C++Memory Operators
new : Is an operator that allocates storage for one or more elements (objects) and then calls the constructor of each element to initialize it.
delete : Is an operator that calls the destructor for each of the stored elements and then frees the associated storage.
As you can see from the above, new is not equivalent to malloc and delete is not equivalent to free . They are not enterchangable and should not be mixed. When writing C++ code you should use new and delete , unless you have a very good reason not to.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|
If you try to write a code, using this option it will compile but at run time the
1) Combination of malloc and delete get crashed
2) If you allocated memory for object using new and try free for deallocating memory there will be memory leakage problem because destructor never call by free
|
|
|
|
|
Combining malloc and delete might not cause a crash - with a couple of the compilers I use I'm pretty sure I can write code that allocates memory with malloc and deletes an object where that block was allocated without a crash. I shouldn't though as it requires a lot of knowledge of how the compiler's runtime works and is about as portable as a suitcase of bricks.
Likewise if I call free on an object I created with new I might not get a memory leak. Yes, the destructor won't be run but the destructor isn't the thing that releases the primary memory of an object.
Ash
|
|
|
|
|
Hello
sry for may bad english im a Austrian
Ok now my question
I have a litle Prog witch opens a txt file from my local hdd, now i want to open a txt file from my web serv and put it out on te consol.
But how can i open the file ?
it doesn't work
ptr = fopen("\\http://king.ath.cx//server.txt" ,"r+");
if(ptr == NULL) {
printf("\nfopen error\n");
getchar();
Lg
Alex
|
|
|
|
|
You must first copy the file onto your local disk, either through your browser or via FTP.
It's time for a new signature.
|
|
|
|
|
I can say one of old style of coding (not a .net style, I'm saying) with WinInet.
The primary usage is thus;
<pre>
HINTERNET hInet = InternetOpen("MyLocalAgent", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
HINTERNET hFile = InternetOpenUrl(hInet, "http://king.ath.cx/server.txt", NULL, 0, 0);
BYTE buffer[BUFSIZE];
DWORD dwRead;
while (InternetReadFile(hFile, buffer, BUFSIZE, &dwRead)) {
if (0 == dwRead) break;
fwrite(buffer, 1, dwRead, stdout);
}
InternetCloseHandle(hFile);
InternetCloseHandle(hInet);
</pre>
|
|
|
|
|
You could either open it using a UNC path, or try using URLDownloadToFile() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
but URLDownloadToFile() cannot down the LAN's web server ,like this : http://192.168.1.200/myfree.txt
|
|
|
|
|
You could use CInternetSession , CSdioFile , CHttpFile and CInternetFile MFC classes to read data from remote file based on HTTP and FTP protocols.
Life is a stage and we are all actors!
|
|
|
|
|
But how can I do it could you help me
|
|
|
|
|
You may start your research from here.
Life is a stage and we are all actors!
|
|
|
|
|
I am creating an activex control using directshow in vc++ mfc.
when I realese the interface IGraphBuilder then application is crashed in windows vista but in windows xp it works fine.
why it is happened .
|
|
|
|
|
> why it is happened .
Os is very different. It is just a reason.
Generally, many program which can run on xp will not be able to run on vista because of incompatibility between xp and vista.
The most incompatibility of os is around security.
Check the API's document you used, and you might find some clue of them; incompatibilities.
|
|
|
|
|
My excel file cell value is changing but I am not getting the change event . value is updating with some other software . is there is any setting in excel file
Trioum
|
|
|
|
|
You must watch every time its file changing if you want know.
I don't know the general watching process for the reason.
So, you can write some code which reads the file and sense difference of it by yourself.
|
|
|
|
|
Hi all,
What I am trying to do is transfer a screenshot over a socket. I can get the screenshot into a Bitmap type, and I can even save it as a JPEG file by getting the CLSID of the encoder. However, I want to do this without an intermediatary file - that is, I want to be able to turn the Bitmap into a JPEG binary array and send it directly over the socket. I'm currently stumped at the turning the Bitmap image into a binary JPEG part - any suggestions would be nice. Or, if there is an easier way to do this that I'm missing, please assist. Been googling for a while now to no avail.
Thanks
|
|
|
|
|
Okay, I've made a little progress:
Gdiplus::Bitmap bitmap(membit, NULL);
CLSID clsid;
GetEncoderClsid(L"image/jpeg", &clsid);
IStream* tmpbuf = NULL;
CreateStreamOnHGlobal(NULL, true, &tmpbuf);
bitmap.Save(tmpbuf, &clsid);
tmpbuf->Release();
How do I change the IStream* into a byte* (and how do I determine the size beforehand)?
|
|
|
|
|
Don't release the IStream*.
Add:
HGLOBAL hg = NULL;
hr = GetHGlobalFromStream(pIStream, &hg);
ULONG uSize = GlobalSize(hg);
and transfer/copy.
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Thanks, it's working great.
Do you have any suggestions on what I can do on the receiving end? I don't want to create a file and I don't want to allocate an entire buffer for the image either. Is there any way I can receive in chunks and still be able to display the whole thing at the end? Sometimes the image gets quite large (>10mb) and I don't want excessive memory usage.
edit: nevermind. it's working now. thanks for all your help!
modified on Sunday, May 23, 2010 12:28 PM
|
|
|
|
|
Hello everybody !
In my dll project,I export some functions, and I used them with the static library in main project,it's normal and have none errors.dll code like this:
unsigned char ParamBuffer[0x5c];
unsigned char SendBuffer[1024];
unsigned char RecvBuffer[1024];
CWaitDlg *g_ProgressDlg;
int InitParams()
{
}
int SetSendBuffer(unsigned char *temp,int nLen)
{
memcpy(ParamBuffer,temp,nLen);
return 0;
}
int ShowDlg()
{
}
int CreateDownThread()
{
...
}
But I used it with dynamic library in the main project,the GUI is hang-up,and the buffer isn't written to the serialport,because I use the Portmon to catch the serial event.
the main project code like this:
typedef BOOL (CALLBACK *MyTxtFormat)(char *,char *);
typedef int (CALLBACK *MyShowLoadingDlg)(BOOL);
typedef int (CALLBACK *MySetSendBuffer)(unsigned char *,int nLen);
typedef int (CALLBACK *MyCreateDownThread)();
typedef int (CALLBACK *MyInitialParam)();
static MyInitialParam InitialParam;
static MyShowLoadingDlg ShowLoadingDlg;
static MySetSendBuffer SetSendBuffer;
static MyCreateDownThread CreateDownThread;
HINSTANCE hCode;
HINSTANCE hHardware;
MyTxtFormat TxtFormat;
void CMainFrame::OnDownload()
{
TCHAR *szpBuffer = new TCHAR [8000];
unsigned char szTemp[4096];
BOOL bRet = FALSE;
CFile pFile;
DWORD nActual = 0;
memset(szpBuffer,255,8000);
hCode=LoadLibrary("aaa.dll");
TxtAAA=(MyTxtFormat)GetProcAddress(hCode,"TxtFormat");
if (TxtToCode)
{
bRet = TxtFormat(strLDPath.GetBuffer(strLDPath.GetLength()),
strBinPath.GetBuffer(strBinPath.GetLength()));
if(!bRet)
{
MessageBox("TxtFormat error!");
return;
}
if ( pFile.Open( _T(strBinPath),CFile::modeReadWrite | CFile::typeBinary, NULL ) )
{
nActual = pFile.Read(szpBuffer, 8000);
}
}
hHardware = LoadLibrary("bbb.dll");
if(hHardware)
{
ShowLoadingDlg=(MyShowLoadingDlg)GetProcAddress(hHardware,"ShowLoadingDlg");
if(ShowLoadingDlg == NULL)
{
MessageBox("ShowLoadingDlg Functioin Failed !");
return;
}
InitialParam = (MyInitialParam)GetProcAddress(hHardware,"InitialParam");
if(InitialParam == NULL)
{
MessageBox("InitialParam Functioin Failed !");
return;
}
SetSendBuffer=(MySetSendBuffer)GetProcAddress(hHardware,"SetSendBuffer");
if(SetPlcRam == NULL)
{
MessageBox("SetSendBuffer Functioin Failed !");
return;
}
CreateDownThread = (MyCreateDownThread)GetProcAddress(hHardware,"CreateDownThread");
if(CreateDownThread == NULL)
{
MessageBox("CreateDownThread Functioin Failed !");
return;
}
ShowLoadingDlg();
InitialParam();
SetSendBuffer(pBuffer,sizeof(pBuffer));
CreateDownThread();
}
pFile.Close();
szpBuffer = NULL;
delete szpBuffer;
FreeLibrary(hHardware);
}
Generally,what causes of this error happend ?
modified on Friday, May 21, 2010 10:32 PM
|
|
|
|