|
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
|
|
|
|
|
I want to be able to recognize when some pane of the statusbar is clicked. I need to know this in my View class which is derived from CView.
Any idea?
Thanks
modified on Friday, May 21, 2010 4:10 PM
|
|
|
|
|
You will probably need to use Subclassing[^] to capture events sent to the statusbar.
It's time for a new signature.
|
|
|
|
|
Hi,
I'm using the following code in visual studio 2008:
std::vector< double >::iterator location;
location=std::find(vec.begin(),vec.end(),0.);
and I'm getting the error:
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::_Vector_iterator<_Ty,_Alloc>' (or there is no acceptable conversion)
My header files are as follows (I know all these aren't necessary for this small portion of code, but the rest of my code requires the additional headers):
#include "stdafx.h"
#include <algorithm>
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <ostream>
Does anyone know how to fix this? Is it possibly a visual studio project setting
Thanks!
|
|
|
|
|
A fresh VC++ 2008 console project compiles the following code just fine:
#include <vector>
#include <algorithm>
int main()
{
std::vector<double> vec;
std::vector< double >::iterator location;
location=std::find(vec.begin(),vec.end(),0.);
}
Also, be careful when comparing floating-point numbers[^]
|
|
|
|
|
|
Hi everyone,
I'm using a vector of vectors to mimic a matrix using the following:
vector < vector <long double> > data_matrix;
I then add "rows" using the following:
for (int z=0;z<13;z++)
data_matrix.push_back(vector <long double>());
Next, I load the appropriate values (from an input file) into the vector of vectors (some the values will be zeroes).
What I'd like to do, is to search a particular "column" for zeroes and eliminate them in that column as well as the corresponding entries in the adjacent columns (so in effect, eliminate an entire row). I've figured out how to delete zeros from any given vector in the vector of vectors using:
bool IsEven (double d)
{
return (d) == 0;
}
data_matrix[0].erase(std::remove_if(data_matrix[0].begin(),data_matrix[0].end(),IsEven), data_matrix[0].end());
Does anyone know how to do this
The number of entries in each of the columns are the same.
Thanks!
modified on Friday, May 21, 2010 12:43 PM
|
|
|
|
|
Can you give us an example of what happens when you, for example, reduce a 3 by 3 matrix like:
1 1 1
0 2 2
3 3 3
Would you expect to end up with the following matrix?
1 1 1
3 3 3
If so you can do it with remove_if on the vector of rows - you remove any row that has a zero element in it. The predicate will have the form:
bool contains_zero( const std::vector<long double> &row )
{
....
}
Cheers,
Ash
PS: If you're using a compiler that supports them you can write the predicate as a lambda rather than as a function.
PPS: Just out of interest you can get rid of the loop:
for (int z=0;<13;z++) data_matrix.push_back(vector <long double>());
Have a look for a constructor for vector that takes a size or consider using std::generate_n to do it all in one fell swoop.
|
|
|
|
|
Hi Ash,
Thanks for replying. You're example matrix is what I'd expect. The way my vector of vectors is set up is that each of the vectors actually contains the data from the particular column (instead of row). This is why I seem to be having trouble.
For example (when referring to your sample matrix):
vector[0] would contain 1 0 3
vector[1] would contain 0 2 2
vector[2] would contain 3 3 3
So for example, the code and predicate that I previously posted which used "remove_if" would make vector[0] = 1 3 which would then give:
1 1 1
3 2 2
3 3
but not:
1 1 1
3 3 3
I should have mentioned that key piece of information (that the vectors hold columnar data instead of row date), sorry about that.
Any ideas for this scenario
Thanks,
|
|
|
|
|
Ouch, it's a bit messier but...
- for each column use std::find to locate any zeros. Record the indices of the rows the zeros are in somewhere, maybe another vector or a perhaps a set. (std::find returns an iterator, you'll have to subtract column.begin() from that to get the index from the iterator).
- for every row there's a zero in, zero every column element in that row.
- for each column use the combination of std::remove_if and std::erase you presented in the question to eliminate the zeros.
Hope that's clear enough - if not feel free to ask what I'm wittering on about,
Ash
|
|
|
|
|
Thanks Ash,
Sounds good, I'll give this a try.
|
|
|
|
|
Hi,
How to change the window title in SDI application dynamically.
Ex : title is MyApp - untitled
I want to change MyApp to some other text.
I can change untitle to any other value but i want to change MyApp
to some other text.
Please help me
|
|
|
|
|
Check out the IDR_MAINFRAME string resource.
"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
|
|
|
|
|
Yes IDR_MAINFRAME string variable will work
but I want to change dynamically?
|
|
|
|