|
Wrong forum.You should post you question to C++/CLI forum.
Life is a stage and we are all actors!
|
|
|
|
|
I did. But no one seems to know.
|
|
|
|
|
voo doo12 wrote: I did. But no one seems to know.
OK.
I would advice you to write your own managed wrapper for of IHTMLElementRender interface, never mix managed and unmaged code, and avoid using C++/CLI for anything- it's not stable enough, it's very slow and inefficient, it's dirty.You are supposed to use C# or VB.NET, when you are targeting .NET platform. If you need to create something using C++ you should better use MFC libraries.Good luck.
Life is a stage and we are all actors!
|
|
|
|
|
Can you show me how I could save image(picture) from webbrowser control using MFC?
|
|
|
|
|
voo doo12 wrote: Can you show me how I could save image(picture) from webbrowser control using MFC?
Of course I can.
In MFC you should use Doc/View framework and CHtmlView class to access HTML using DOM.
[EDIT]I used Gdi+ to handle the images[/EDIT]
Here is my demo sample:
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0;
UINT size = 0;
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0)
return -1;
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL)
return -1;
GetImageEncoders(num, size, pImageCodecInfo);
for(UINT j = 0; j < num; ++j)
{
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j;
}
}
free(pImageCodecInfo);
return -1;
}
void CWebBrowserAppView::OnFileSave()
{
LPDISPATCH pDisp=GetHtmlDocument();
IHTMLDocument2* pDoc;
HRESULT hr=0;
hr=pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDoc);
if(FAILED(hr))
{
pDisp->Release();
AfxMessageBox(L"Sorry dude, cast failed!");
return;
}
IHTMLElementCollection* pImgs;
hr=pDoc->get_images(&pImgs);
if(FAILED(hr))
{
pDoc->Release();
pDisp->Release();
AfxMessageBox(L"Sorry dude, can't get images list from document!");
return;
}
long length;
pImgs->get_length(&length);
IDispatch *pdImg;
IHTMLImgElement *pImg;
CLSID jpgClsid;
GetEncoderClsid(L"image/jpeg", &jpgClsid);
for(int i=0;i<length;i++)
{
_variant_t index = i;
hr = pImgs->item( index, index, &pdImg);
if(SUCCEEDED(hr))
{
hr= pdImg->QueryInterface( IID_IHTMLImgElement, (void **) &pImg);
if(SUCCEEDED(hr))
{
long width,height;
pImg->get_width(&width);
pImg->get_height(&height);
IHTMLElementRender* pRend;
hr=pImg->QueryInterface(IID_IHTMLElementRender,(void**)&pRend);
if(SUCCEEDED(hr))
{
Bitmap* pBmp=new Bitmap(width,height,PixelFormat24bppRGB);
Graphics* pGr=Graphics::FromImage(pBmp);
HDC gDc=pGr->GetHDC();
hr=pRend->DrawToDC(gDc);
pGr->ReleaseHDC(gDc);
if(SUCCEEDED(hr))
{
CString name;
name.Format(L"%d.jpg",i);
pBmp->Save(name,&jpgClsid,NULL);
name.ReleaseBuffer();
}
pRend->Release();
delete pBmp;
}
pImg->Release();
}
pdImg->Release();
}
}
pImgs->Release();
pDoc->Release();
pDisp->Release();
}
Life is a stage and we are all actors!
modified on Sunday, June 6, 2010 9:14 AM
|
|
|
|
|
Thanks very much. I'm not familiar with MFC but I will be. Thanks again
|
|
|
|
|
You are always wellcome.Study hard and you will get results.
Life is a stage and we are all actors!
|
|
|
|
|
Hi, I'm getting "0xC0000138: Ordinal Not Found" when deploying an executable that uses an ActiveX control on another machine. I have no idea where to start debugging this problem.
Basically, what happens is that the visual studio output window displays
"Loaded (correct)path_to_ocx file"
"First-chance exception at 0x7c964ed1 in project_name.exe: 0xC0000138: Ordinal Not Found."
"project_name.exe: Unloaded 'path_to_ocx'"
The problem is that this does not happen on the development machine
Any kick in the right direction would be a godsend. Thanks
|
|
|
|
|
eusto wrote: Hi, I'm getting "0xC0000138: Ordinal Not Found"
As you have probably figured out by now that error essentially means: "I found that DLL you need and I loaded it. But when I walked the export table I could not find one of the functions that you need."
eusto wrote: Any kick in the right direction would be a godsend. Thanks
I would recommend using Dependency Walker[^] on the target machine to track down the problem. You should open the OCX file and look for missing dependencies.
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you for your answer, Dependency Walker is cool, i didn't know about it. Unfortunately, there doesn't seem to be any missing stuff on that ocx. I've contacted the vendor and asked them about it
Regards,
Eugen
|
|
|
|
|
Hi Eugen,
Did you try the Profiling option in the Dependency Walker system menu? This option should allow you to log everything... including calls to LoadLibrary and GetProcAddress. You should point it at the executable loading the OCX object.
Best Wishes,
-David Delaune
|
|
|
|
|
Ok, at this point i'm almost sure this is a vendor issue because recompiling my application on the target machine gets rid of the problem. I'm now betting on a weird licence implementation issue.
Thanks again for your help David.
Regards,
Eugen.
|
|
|
|
|
eusto wrote: Ok, at this point i'm almost sure this is a vendor issue because recompiling my application on the target machine gets rid of the problem.
You may be correct. However, what this would imply to me is that the vendor is dynamically linking with CRT/ATL. I would suggest testing on a third target computer and installing the Visual Studio redistributable package that matches your compiler version.
Microsoft Visual C++ 2008 Redistributable Package (x86)[^]
Microsoft Visual C++ 2005 Redistributable Package (x86)[^]
If your asking yourself why the vendor does not static link... its probably because there have been some recent severe ATL security vunerabilities. By dynamic linking... the vendor can rely on Microsoft updates to potentially fix the issue.
Active Template Library Security Update for Developers[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Hello ,everyone !
Now I want to covert some strings, Just like this:
LPCSTR GetDate(int nTemp)
{
LPCSTR lpstr;
CString str = "";
str.Format("%d",nTemp);
...
}
Thanks for your reply !
|
|
|
|
|
See here[^], it's all in the documentation.
It's time for a new signature.
|
|
|
|
|
|
You're welcome. For future reference it's alway best to try the MSDN documentation first, then Google and/or the articles on CodeProject. Then if it's still not clear come here and ask the 7,000,000 or so experts for help.
It's time for a new signature.
|
|
|
|
|
|
Don't convert to a C style string until you really have to - you might be able to avoid fiddling around with new[] and delete[] and the good source of bugs that is. Usually you want a LPCSTR (ack, const char *) because you want to pass it to some legacy API that doesn't understand C++ style strings. If that's the case leave the conversion to just before you need the pointer to the characters you're after.
Cheers,
Ash
|
|
|
|
|
OK, this is basically algorithm related question and not the code.
Dunno if that is the correct section to post this but i'll try my luck
So, the thing i am trying to do is to parse | interpret JS - and i am pretty new to this.
I just need your advice if i am on a good way. Lets say we have 1 .js file with a function:
function concat_text(some_input_param){<br />
var value = "input text is: ";<br />
var output = value + some_input_param;<br />
return output;<br />
}
silly function. And its saved in a file silly.js
Next, in our index.html we have the following :
<script src="silly.js"></script><br />
<script><br />
var result = concat_text("some test text");<br />
document.write(result);<br />
</script>
Easy right? Ok, so what am i doing now? (all coding done with [C] btw)
1. getting first script source path (for ex. localhost/silly.js)
2. fetching this file (silly.js) content into predefined buffer for JS
3. next fetching second script source (between tags) and appending it to my JS buffer
4. define document.write function and pass the definition into JS interpreter
(in this case as all i need is to get output i can easily even skip that part
and just return the result into interpreter output buffer)
5. pass JS buffer into JS interpreter (i am working with google's V8)
6. .. and just get the result
Is it the right way? Or maybe there are different and more sufficient ways of doing it?
Like, there is no problem when we have a JS script on just one page and there no references
to another JS file, but i am thinking - how about for example, if there is ref to JQuery?
Fetching all its content - scary thing - it so big I am just pretty new to all this JS parsing stuff
and need someones advice.
Thanks in advance.
<div class="signature">011011010110000101100011011010000110100101101110
0110010101110011</div>
|
|
|
|
|
Let's see. The title of your message says "javascript." The title of this forum is "C / C++ / MFC." Is there something there you don't understand? Do you notice anything odd about those 2 pieces of information?
There's another forum called "Web Development[^]" and the description is "Discussions on AJAX, ASP, HTML, Javascript etc." I wonder what they might discuss over there?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
You see, thats the problem! I am not sking about web development and title of my topic is:
Messing with javascript.
Messing with javascript may mean that i am trying to do some manipulations on javascript
from C application, so, from c or c++ code in fact. But, there is one but, that is i am not asking,
for example, "guys, c'mon, give me the code, or, better, complete solution how web browser parses javascript". I could name my topic this way: Javascript parsing in c++ - out of curiosity, would you interpret the very first word of such kind of title and send me to web development section yet again?
So, i dont need the code because i can write my very own, the only thing i have asked about - is my algorithm is fine?
P.S. i would understand if you would direct me to General It Discussions, but, please, my question is not about Web Development
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
csrss wrote: Messing with javascript may mean that i am trying to do some manipulations on javascript
from C application
And it may mean something else. There is nothing in your original question about C or C++ so perhaps you could rephrase it to show what bits of C/C++ code you are having a problem with.
It's time for a new signature.
|
|
|
|
|
It is pointless...
None of you have read my question even.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Had you called your original question something like: "Invoking javascript from a C application" or "Calling javascript functions from C" people might have read it a bit more carefully and not deployed sarcasm.
Cheers,
Ash
|
|
|
|