|
Thanks for the quick response. I'm doing some reading and I'll post back whether this is a solution or not.
|
|
|
|
|
PogoboyMtK wrote: we have an sdk provided by the vendor, who unfortunately no longer exist so it is completely unsupported.
After patching a solution, have a long hard discussion with the power that be in your company to find a replacement for that faulty SDK.
Watched code never compiles.
|
|
|
|
|
I agree 100%. My issue is that the sdk is tied 100% to the db which is 100% tied to the product which is 100% tied to the users which is simply not an option to upgrade.. I don't know whether to laugh or cry about that one.
|
|
|
|
|
This might sound disgusting but maybe you could try hooking the memory allocation API calls "under the hood", i mean things like GlobalAlloc or HeapAlloc and somehow keep track of the memory allocation/deallocations the third party does and when you get back the control (so execution comes back from the third pary call), investigate what memory allocations were left undeallocated and deallocate them yourself.
I already did such hooking magic a few times in my life so in case you are interested, i am willing to try and help doing this, it sounds like a challenge.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
I would love for the help, but due to confidentiality issues I can't take you up on it.
Thank you for the offer, though.
Anytime someone tells me some code will be "disgusting" or "really ugly", etc. I become very much intrigued by the challenge of making it pretty and manageable.
modified on Wednesday, October 13, 2010 2:52 PM
|
|
|
|
|
I didn't mean the code would be ugly, i meant the concept itself. Anyways, i can still try to give you the idea, maybe you can use it, maybe not, that is up to you to decide, so here's what i would do.
1. Try to determine where the memory leaks come from by trial and error (i mean, what 3rd party call, i supose you already know that, so you can skip this step)
2. Install hooks for the allocation/reallocation/deallocation methods listed here[^], see API hooking revealed[^] for hooking methods (since you are working within your own process -i supose- you don't need the DLL injection part). Depending on that SDK you might need to do the hooking for multiple modules (DLLs), again, this is up to you to determine. Since malloc/new come down to these memory management functions, this should suffice to "catch" all memory allocations.
3. In my hook functions, i would call the originals to perform the actual memory management, but i would add every allocated pointer to some array of my own, remove them when they are freed, replace them when reallocations are done. I would make this conditional based on some global flag (or such) so when it is unneeded (when no 3rd party code is executing) it doesn't take up resources uselessly.
4. Before the 3rd party call, i would turn the "allocation tracking" mentioned in point 3, let the 3rd party thing finish, turn off the tracking thing, and then analize the array i used for the pointers. If my assumptions are correct the array should contain pointers to the buffers which aren't freed up and then i could just free them up myself (be careful to use the correct methods for the deallocation, so if e.g. a pointer was allocated by HeapAlloc then use HeapFree, if VirtualAlloc then use VirtualFree).
What might go wrong is that if the 3rd party thing e.g. calls CRT's malloc, and that calls HeapAlloc, which in turn calls VirtualAlloc, and you hooked both HeapAlloc and VirtualAlloc, then you might "hit" the same pointer twice, another thing that can be -and i am afraid will be- a problem is that -as far as i know- CRT doesn't actually free up memory when you call free (or at least not always) but it somehow flags it internally for himself to be free and will reuse it later, sadly as far as i know you can't hook malloc/free.
This whole idea requires some experimenting i am afraid. In case you decide to try it, please do tell me how it went, i am curious. Good luck, if you should have any questions, feel free to hit me in the head with it.
[EDIT] If your third party SDK doesn't link statically to CRT (so uses the DLLs) then you might even hook malloc/free/realloc too. [/EDIT]
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
modified on Wednesday, October 13, 2010 4:47 PM
|
|
|
|
|
Code-o-mat wrote: feel free to hit me in the head with it
I might take you up on that. I'm tired of doing it to myself all the time.
|
|
|
|
|
I'll just put on my headbanging helmet...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
Hey, sorry for being nosey but i am just curious, could you solve this problem in the end, and if yes, how did you?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
|
|
|
|
|
Actually, I haven't found a permanent solution yet and I don't know if I'll be able to find the time to do it, which really sucks because this is going to eat away at me until I can find a solution.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Hi!
I've to display a wide char string as right justified. How to do this?
|
|
|
|
|
take a look at the documentation for the function you would use to draw it without justification of any kind and see if it support right-justification.
if not, see DrawTextEx[^]
|
|
|
|
|
Chris Losinger wrote: see DrawTextEx[^]
I think this function can be used if I configured a MFC project? I'm not supposed to use MFC.
|
|
|
|
|
DrawTextEx is not an MFC function
|
|
|
|
|
It is just a plain Windows API function (CDC::DrawTextEx is a MFC method).
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]
|
|
|
|
|
It really depends what you are using to display the string. A string is not justified, it is just a sequence of characters. You have to draw the string somewhere in order to display it justified. How to do that really depends on what API you are using to draw or display the string. So, if you tell us how you draw the string then maybe will be able to help.
|
|
|
|
|
The above code works fine if no proxy authentication at server side. It fails as soon as proxy authentication is applied.
Please help me to sort out whre i am wrong. Any kind of help appreciated.
CInternetSession ises(NULL,1,INTERNET_OPEN_TYPE_PROXY, _T("192.168.9.10:8080"),NULL);
CFile* file=new CFile();//There might occur a connection error
try
{
CString url = _T("http://someurl.com/somepath";)
DWORD dwFlags = INTERNET_FLAG_TRANSFER_ASCII | INTERNET_FLAG_EXISTING_CONNECT;
file = ises.OpenURL(url);//CInternetSession::OpenURL(url) returns a source code in CHttpFile;
}
catch(CInternetException* e)
{ //If an error occured, show messagebox with errorcode
} //catch(CInternetException *ex)
catch(CException *ex)
{
WCHAR str[500];
DWORD errorCode = GetLastError();
ex->GetErrorMessage(str, GetLastError());
AfxMessageBox(str);
}
CString result;
UINT len=1024;
char buf[1024];
source=L"";
while(len > 0)
{
len=file->Read(buf,1024);
if(len>0)
result.Append(CString(buf),len);
}
file->Close();
ises.Close();
Thanks and Regards,
Amar Mhetre
|
|
|
|
|
try below code to set proxy settings,may be it will help you...
CInternetSession ises;
INTERNET_PROXY_INFO proxyinfo;
proxyinfo.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
proxyinfo.lpszProxy = "192.168.9.10:8080";
proxyinfo.lpszProxyBypass = NULL;
ises.SetOption(INTERNET_OPTION_PROXY,(LPVOID)&proxyinfo,sizeof(INTERNET_PROXY_INFO));
|
|
|
|
|
Thanx for your reply.
This will set the proxy, but my problem may be to set the credentials for the proxy ( username and password ). THe way "ises.SetOption()" fails for INTERNET_OPTION_PROXY_USERNAME and INTERNET_OPTION_PROXY_PASSWORD. Is there any other way to set user name and pasword.
Thanx once again for ur reply.
|
|
|
|
|
|
Thanks for the links. I allready gone through the links and found solution.
It should as follows....
HINTERNET hOpenHandle, hConnectHandle, hResourceHandle;WORD dwError, dwErrorCode;
hOpenHandle = InternetOpen(NULL,INTERNET_OPEN_TYPE_PROXY, _T("192.168.9.10:8080"), NULL, INTERNET_FLAG_SECURE);
// _T("192.168.9.10:8080") is proxy with port number
DWORD dwServiceType = AFX_INET_SERVICE_HTTP;
CString szServer, szObject;
INTERNET_PORT nPort;
AfxParseURL (strURL, dwServiceType, szServer, szObject, nPort);
// strURL is any URL whose data to retrieve say http://www.google.com
hConnectHandle = InternetConnect(hOpenHandle,szServer,INTERNET_INVALID_PORT_NUMBER,
_T("test1"), _T("test"), INTERNET_SERVICE_HTTP, 0, 0);
// _T("test1"), _T("test") is username and password for proxy at my server
hResourceHandle = HttpOpenRequest(hConnectHandle, _T("GET"), szObject, NULL, NULL, NULL,
INTERNET_FLAG_KEEP_CONNECTION, 0);
resend:
HttpSendRequest(hResourceHandle, NULL, 0, NULL, 0);
DWORD dwStatus;
DWORD dwStatusSize = sizeof(dwStatus);
HttpQueryInfo(hResourceHandle, HTTP_QUERY_FLAG_NUMBER |
HTTP_QUERY_STATUS_CODE, &dwStatus, &dwStatusSize, NULL);
dwErrorCode = hResourceHandle ? ERROR_SUCCESS : GetLastError();
dwError = InternetErrorDlg(this->GetSafeHwnd(), hResourceHandle, dwErrorCode,
FLAGS_ERROR_UI_FILTER_FOR_ERRORS | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS | FLAGS_ERROR_UI_FLAGS_GENERATE_DATA, NULL);
if (dwError == ERROR_INTERNET_FORCE_RETRY)
goto resend;
DWORD dwNumberOfBytesRead;
char sz[1024];
int result;
do
{
result = InternetReadFile(hResourceHandle, sz, 1023, &dwNumberOfBytesRead);
sz[dwNumberOfBytesRead] = '\0';
int x = strlen(sz);
strResult += sz;
memset(sz, 0, 1024);
} while(result && dwNumberOfBytesRead != 0);
return strResult;
I was trying/searching this for two days and finally this is done. For others who want proxy authentication, can refer this code. But still there has to be a way by using CInternetSession as it is wrapper to WinInet API's used above. I am happy now that code is working fine now.
Thanks once again for your help.
|
|
|
|
|
In a dialog box application, a text box is placed on dialog and CString variable is used for text box.
To update data in text box i write some value in CSting variable and call UpdateData(False). But it gives assertion error in debug mode. No error in release mode. How to solve it.
There is a button on dialog box and onclick function for this button. In onclick function for button i call one function say disp. disp function display another dialog (call its DoModal()). When another dialog display i click on cancel button and it works fine.
I also call disp function from pretranslate message (for any key press). When disp function display another dialog and i click on cancel button an error occur (wincore.cpp). Why this error comming. How to avoid that
|
|
|
|
|
You could start by telling us which assert fails. What does it say?
|
|
|
|
|
I'll check what's error message and update here
|
|
|
|
|
MKC002 wrote: To update data in text box i write some value in CSting variable and call UpdateData(False). But it gives assertion error in debug mode. No error in release mode. How to solve it.
You could start by using a CEdit object instead (of CString ) and simply call its SetWindowText() method. Much cleaner and less prone to error.
"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
|
|
|
|
|