Visual C++ :: Read JPG As Binary In MFC App And Send To JavaScript Function In HTML Page?
Sep 6, 2013
I am writing an MFC app in Visual Studio 2012 that will open a JPG file as binary and read all the contents to a CString.
I am able to read it to a std::Vector, but that doesn't work much as i need to pass all the binary content as a MFC CString to another function.
More Update:
Let me explain the problem a little more deeper.
I am trying to call a JavaScript (JS) function in a HTML page and then want to pass the binary date. The C++ function that calls the JS is given below.
The 1st argument is the JS Function Name and 2nd is the one to pass the Binary Data. 1st argument works fine as i am able to call the JS fucntion called "LoadImage" without any problem. Problem is with 2nd argument that's supposed to take the Binary data of the JPG file.
If i try to pass a std::Vector or std::string then it will give me an error.
But it's happy if i pass CString. But then with CString there's a problem with NULL characters.
Actually my plan is to pass the binary of a JPG to a JS function and let it display the JPG in the HTML page.
Can i typecast a Vector or std::string to a CComVariant*?
How can I read text from a webpage asynchronously,from within C++. After you first connect to the internet using usual means, you enter the string
e.g. "[URL] ...." and the C++ program reads the information: "<title>BBC Website</title><body>This is the BBC website...." from the internet.
Here I want to connect to website every 60 minutes and fetch only first 100 lines of the run.txt file as mentioned above. How can I do this using C++ and asynchronous winsock ???
Code: #define WIN_OS #define _DEBUG_PRINT(X) /* X */
I created a MFC dialog using CDHtmlDialog and added a HTML page with many controls and one of them is a IMAGE tag. I got a default image loaded from the hard drive displayed in the HTML page. Up to this part, everything works fine.
Now what i want to do is, dynamically change the image based on the user click on one of the HTML buttons. I don't want this image source to be hard coded in the HTML nor the image source send from the MFC app.
What i want is for the MFC app to send the image data to the HTML in some (binary) format and then the page to display the image.
The possible option i was thinking of was to read the image file which is already in my hard drive as a binary file and send the binary data across to the HTML as a memory buffer, and then use JavaScript to decrypt this binary data and display the image.
Basically what i want is for the HTML page to display a image from the memory. how to do this?
I would like to be able to call c++ library from HTML page. So on HTML page I have area for some possible input (url, name, email, etc) and that info is passed to c++ and calculated info and may email someone; or pull info from text file and display on html page. Realizing PHP or something similar would be easier, I really want to make these calls from HTML pages. ???
I'm working on a CGI application. I'm trying to test my input with a switch statement and output the result with html tags to populate a web page. From within the switch, I've coded as follows:
HTML Code: switch(mFunc) { case 0: cout << "<p><b>YOU ENTERED THE FOLLOWING TO BE CALCULATED:</b></p>" "<h2>"<< number1 <<"+" << number2 << "</h2>" << endl; break; case 1: cout << "You've entered" << number1 <<"-" << number2 << "to be evaluated" << endl; break;
I know that I'll need to put this in an html body with a content type as such:
Is there a way I can do message processing between a Win32 application and Javascript using some Windows CallBack function or using Send or Post message?
I have to write a c++ program to read html code and do bunch of stuff. One thing that i have to do is to count the no of attributes and sort them in descenting out and print out only first 10 frequently used attributes. I counted them using maps and sorted them using multimaps but now dnt knw how to print only 10 elements
for(std::map<string, int>::iterator it = Element.begin(); it != Element.end(); ++it) Elements.insert(pair<int, string>(it->second, it->first)); for(std::multimap<int, string>::reverse_iterator it = Elements.rbegin(); it != Elements.rend(); ++it) { cout << "Element: " << it->second << " : " << it->first << endl; }
This is how i did it . How to display only 10 elements and not all the elements.
I am writing a client-server program in C++ using C libraries. The server listens for a connection and when one is found, it is supposed to send a binary file(an image in my case) to the client. The server is sending the binary file perfectly after opening it and reading its contents into a buffer that is dynamically allocated in the SERVER file.
The problem begins when the client file is supposed to recv() the file, I do not know how I can allocate a buffer big enough for the file to be received. I know how to use malloc() and new, I prefer malloc() for executable size customization. Assuming the file being sent is 11000 bytes(note that this is an assumption and the client can not know the file size because the file size is dynamically generated by server).
How can the client generate a dynamically allocated buffer big enough to hold 11000 bytes? OR How can the client store the data in a buffer using recv() without knowing the file size.
Below is part of the code that does the send()'ing and recv()'ing.
SERVER
FILE *img = fopen("img.jpg", "rb"); fseek(img, 0, SEEK_END); unsigned long filesize = ftell(img); char *buffer = (char*)malloc(sizeof(char)*filesize); rewind(img); // store read data into buffer
[Code] ....
This outputs all the binary code perfectly but it is a bug because it can't be written to a file. Is there a way to dynamically increase the buffer until all filesize is received? Certainly, buffer needs to be dynamically allocated or program crashes ...
Also one more thing, when I telnet the server from command line, telnet displays all the output perfectly as well
Maybe telnet is storing data into a buffer behind the scenes, if so, how?
I m making calendar in server control page by taking composite control.I am also adding textbox in each cell of calendar. Now i want to access the value of each textbox of selected month and respected date in default.aspx page on button click event. Here the button is not a custom control but defined in default.aspx page..
Can't access textbox text and date or controls of server page in website(default.aspx) page.
I found the following code in [URL] ....., that send .TXT files perfectly to php script in my server using Wininet, but when I insert a .BMP file, this file (.BMP) is correctly created and named in server side, but it is empty! I read that is necessary implement base64 encode for work properly, so how would?
This is stored in a malloc'ed char *. To add the binary data I'm using fread: fread(request + strlen(request), 1, size, fp)
I then write 'total' bits via connfd:
write(connfd, request, total) where total = strlen(headerRequest) + size + 3 (for ending ).
The writing seems to be okay however the image doesn't load and the browser still seems to be waiting for data.
If I added "Connection: close" to the header and closed connfd myself the page loads fine. Obviously, for efficiency purposes, I'd rather only close connfd once read() returns 0.
I tried to do this with _spawnl(), but first of all I'm not sure how to properly ask for the path to iexplore.exe, as I'm sure it will change every time MS gets a whim to move it. I know there's a GetWindowsDirectory() call, but that's not where IE resides (its in "C:Program FilesInternet Exploreriexplore.exe" in XP, Lord know where on win 7 or 8).
Also, even temporarily hard coding the path to make it launch with spawnl(), I can't seem to get my html document to display. I know the path to that is right (since I put it there ).
I am unable to implement the insert function properly,every time i run the program i just get the first value and name,i am not getting other Id's and name.
Code: "(Header File)" #include <iostream> #include <string> using namespace std; class node { public: int ID; node (string StudentName, int IDNumber) {
When i click the back button, I like to skip some old pages & rotate pages view in my property sheet.
I have 5 pages, when i clicked the User button in my MainDlg the below function called like, User Button Clicked -> Page1 Opened Next Button Clicked -> Page2 -> Page3 -> Page4 -> Page5 Back Button Clicked Page1 <- Page2 <- Page3 <- Page4 <- Page5
My requirement is, User Button Clicked -> Page1 Opened Next Button Clicked -> Page2 -> Page3 -> Page4-> Page5 -> Page1(Again called 1st page automatically - rotate pages view) Back Button Clicked(Cur Page loc is Page5) (Start the prev Process)Page5 <- Page1 <- (Skip the Page2 & 3)Page4 <- Page5
I'm making a small MFC module that should generate a report (formatted using HTML) and then display it for a user on schedule at 8:30 AM every day. Pretty straightforward stuff.
I compose my report and then save it as a local HTML file in the CSIDL_APPDATA folder. I then use the following calls to display it using the default web browser (Internet Explorer in this case):
Code: //Error checks are omitted for brevity CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); ShellExecute(NULL, NULL, strSaveFileTo, NULL, NULL, SW_SHOWNORMAL);
This module is run on schedule from the Task Scheduler. (The task is set up to run when a user is logged on, which is all the time for that PC. It is never turned off, put to sleep, etc. That computer has only one user that is never logged off either.)
This works perfectly fine when I test it by setting the task a minute or so in the future. But when the actual task is supposed to run at 8:30 AM, when the user wakes the screen all they see is a blank Internet Explorer page. (Note that if someone refreshes that page by hitting F5, only then my report is shown on the screen.)
So I started looking into it:
1) I checked that the file is properly saved (before calling ShellExecute) by reading it back and by comparing it with the original HTML markup that I saved earlier. It's all correct there.
2) I then checked the power saving options. That computer is set up to show screensaver after 5 minutes and to turn off screen after 25 minutes.
3) The web browser that causes this issue is IE version 11, with the latest updates installed. The operating system is Windows 7 Professional.
And why is IE showing a blank page only when computer is running unattended?
I have struggled to send email from my MFC applications using severl methods:
1) http via my server - works but limited 2) M$ Outlook automation - works but not easily interchangeable between machines 3) Windows Sockets - available information simply too complicated 4) Purchase an ActiveX control - I hate black box solutions and am too cheap
I have looked at P. J. Naughter's class CPJNSMTPConnection v2.99 An MFC class to encapsulate the SMTP protocol [URL]
This approach requires the implementation of OpenSSL which turns out to be nothing short of a nightmare to install (so I never got it to run). I am looking for an example of an application that utilizes SMTP via Windows sockets api.