|
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
|
|
|
|
|
Try calling GetLastError and passing the result through FormatMessage - that'll give you an idea of why LoadLibrary's failing. Generally it's because it can't find the library.
Cheers,
Ash
|
|
|
|
|
You have shown the code for your main program that calls the DLL but you have not indicated where it has stopped or what the code in the DLL is doing. Try stepping into the DLL code with your debugger to see why it is hanging.
It's time for a new signature.
|
|
|
|
|
Check the calling convention of those exported functions.
The default calling convention is __cdecl but some API function requires __stdcall .
|
|
|
|
|
Assume the following:
In a computer called COMPUTER there is the following folder:
c:\folder1\folder2
Now, there are 2 shares:
\\COMPUTER\NetFolder2 --> which is c:\folder1\folder2
\\COMPUTER\NetFolder1 --> which is c:\folder1
Now, I can get to through the network to "folder2" in 2 different ways:
\\COMPUTER\NetFolder2
\\COMPUTER\NetFolder1\folder2
Is there a way to check that \\COMPUTER\NetFolder2 is the same as \\COMPUTER\NetFolder1\folder2 ???
Thanks!
|
|
|
|
|
Does PathIsSameRoot() help?
"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
|
|
|
|
|
Hey, Thanks for your help!
No it doesn't help...
Well, I am happy to say that I just found out that Boost library can do that using boost::filesystem::equivalence() function.
But my main problem still remains...
How to tell that NetFolder1 is NetFolder2's parent?
(it is possible to iterate all the shared directories and create a data structure that will hold that data, but when there are many shared folders, it is almost insane!)
Thanks Again!!!
|
|
|
|
|
Hello,
I was wondering if some one can point me to the right direction to implement something similar to page layouts in MS word. I am more interested in the print layout.
Thanks
Mohamed
|
|
|
|