|
Hi,
I want to pass a metafile to an ATL server, so I encapsulated it on a PictureBox object, and then saved it on one IStream, then I try to recover it in the ATL object, and it gives me on error, the code that I use is:
MFC client:
if(IPict) {
IStorage *pIStg;
Res = ::StgCreateDocfile(NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &pIStg);
if(pIStg) {
IStream *TempStream = NULL;
Res = pIStg->CreateStream(OLESTR("MyPicture"), STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0,0, &TempStream);
IPict->SaveAsFile(TempStream, TRUE, NULL);
m_GDIGr.SetMetafile(TempStream);
}
}
ATL Server:
STDMETHODIMP CGDIGraphics::SetMetafile(IStream *pStream)
{
IPicture *Pict = NULL;
HRESULT Res = ::OleLoadPicture(pStream, 0, FALSE, IID_IPicture,(void **) &Pict);
if(Pict) {
::MessageBox(NULL, "PICT", "PICT", MB_OK);
}
return S_OK;
}
What I had made wrong ?, Thanks in advance, Bye !
Braulio
|
|
|
|
|
Hi Braulio
Braulio Díez wrote:
it gives me on error
You didn't mention what is that error
Anyway,Did Dr.Grimes reply you?If the answer is yes would you please tell the answer too?
Thanks
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Hi,
Well the error message is quite dissapointing...
0x8000ffff E_UNEXPECTED
Dr. Grimes didn´t answer me, but well, I keep on researching, and it seems that you have to encapsulate the metafile in a PictureBox control ( IPicture), and the destination is not in the same DLL so I need to save the object in one stream ( I use for that IStream), and then in the ATL server I take that string and try to load the pic...
But... I when I´m going to read from the stream it doesn´t...
I know this is a quite common issue, just to pass a metafile from one process to another using COM, it´s one of the basic thing from COM, the sad thing is that anybody that knows the answer wants to give a hint....
Thanks for you interest mazdak, Bye !
Braulio
|
|
|
|
|
Hi:
Sorry,my ATL knowledge is not enough to help you.
It's very dissapointing that although there are lots of expert in CP but it seems
non of them (or few of them) have good ATL knowledge.
There are about 30000 members in this site...
Good luck and Bye
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Hi Mazdak !
Finally I got the solution, Joao Vaz give me one URL to a nice article, and now it is working nice !!! ( there were some magic with the streams XDDD ).
I have to tidy up all the code and make a submission to codeproject. Bye !
Braulio
|
|
|
|
|
Hola !
As I promised you I Wrote the article about Streams and Pictures and ActiveX, you can check it out in:
http://www.codeproject.com/useritems/PictureTransfer.asp
The bad thing... something went wrong with the submission wizard and the Picture and the zip with the source is not there ( I sent one e-mail to chris with the files, let´s hope he fixes it).
Bye !
Braulio
|
|
|
|
|
Braulio, just one thought , you tried to create the stream on global memory
with the CreateStreamOnHGlobal and get the global handle from the server with
GetHGlobalFromStream , this without using Stg ?
Joao Vaz
|
|
|
|
|
Hi,
Thanks for the tip, I´m trying it now, but it gives me the same error, here it is the code that I use now:
MFC Client:
IStream *TempStream = NULL;
CreateStreamOnHGlobal (NULL, TRUE, &TempStream);
HGLOBAL hMem = NULL;
GetHGlobalFromStream(TempStream, &hMem);
LPVOID lpData = GlobalLock(hMem);
HRESULT HRes = IPict->SaveAsFile(TempStream, TRUE, 0);
GlobalUnlock(hMem);
m_GDIGr.SetMetafile(TempStream);
ATL Server:
STDMETHODIMP CGDIGraphics::SetMetafile(IStream *pStream)
{
IPicture *Pict = NULL;
HGLOBAL hMem = NULL;
GetHGlobalFromStream(pStream, &hMem);
LPVOID lpData = GlobalLock(hMem);
HRESULT Res = ::OleLoadPicture(pStream, 0, FALSE, IID_IPicture,(void **) &Pict);
GlobalUnlock(hMem);
I don´t know where I made the mess , ( I´m pasting the activeX in an automated Ms Word instance and from my app calling the method to insert the activex, all this should be easy-pc for Com isn´t it ? )
Thanks, Bye !
Braulio
|
|
|
|
|
|
Hi Joao !
I had that article before, but well I read it again, and you were right !!!, there is the solution !!!, thanks a lot !
See you and obrigado !
Braulio
|
|
|
|
|
Cool , now you can post a article on Code Project
Cheers,
Joao Vaz
|
|
|
|
|
Hi Braulio, unfortunately seems like most of us in this forum are COM-impaired but I'm following your investigations with great interest, and doing a little research myself. I've just sumbled upon these two functions:
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/cmf_a2c_88tp.asp">CoMarshalInterThreadInterfaceInStream</a> ,
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/cmf_a2c_1rjh.asp">CoGetInterfaceAndReleaseStream</a> ,
which seem to do the job of packing and unpacking an object with the aid of an IStream to pass things across threads. Maybe they're worth having a look at. Good luck.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for the tip !
MMm..., I don´t know too much about marshaling, but well it´s good time to start learning, I think I have to use maybe something like "CoMarshalInterface", because I have different process, I have:
MyApp -( Different Space Proccess)-> Word Automated Instance --> MyDll
I´m advancing but very slow, but now I can paste the ActiveX in a Word automated instance, modify it from my app, and even make serialize it !, the last step it´s to do something useful XD, like for example get the picture...
I swear that if I get all this things up and running I will write a mega article for codeguru talking about this stuff
Thanks for the help Joaquin, Hasta luego !
Braulio
|
|
|
|
|
I swear that if I get all this things up and running I will write a mega article for codeguru talking about this stuff
codeguru?
Suerte con la historia ésta, seguro que cuando acabes tendrás mogollón de información para un buen artículo.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
HOOLA !!!
Ooops, sh*t not codeguru... CODEPROJECT OF COURSE
I GOT IT !!!!, It is working now, thanks to the article ( "Using Picture Objects in ATL", from VBPJ, page 102, wow it´s not so easy to make work the streams and streams persists).
Ahora tengo que ajustarlo para que no pierda memoria ni recursos, y en cuanto lo tenga voy a hacer un pedaaasssoo de artículo... XDDDD
Hasta luego, y gracias por los ánimos !
Braulio
|
|
|
|
|
enhorabuena chaval
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Congratulation!
I'm waiting for that article ,come on Braulio,but I want it here in COPDEPROJECT not codeguru.
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Joaquín , these two functions doesn't work outside processes neither the preferred way of IGlobalInterfaceTable::RegisterInterfaceInGlobal.
He's doing the right thing, i must be a minimal error, that can't spot, i used to program in COM an ATL, but i don't touch it for about one year, and man, we can forget a lot of things that was trivial in past
Regards, Joaquín and continue your good work here at VC++ forum helping the guys . You and James T. Johnson (on the C#) are the most active guys, of course not counting Nish too
Joao Vaz
|
|
|
|
|
Hola !
As I promised you I Wrote the article about Streams and Pictures and ActiveX, you can check it out in:
http://www.codeproject.com/useritems/PictureTransfer.asp
The bad thing... something went wrong with the submission wizard and the Picture and the zip with the source is not there ( I sent one e-mail to chris with the files, let´s hope he fixes it).
Bye !
Braulio
|
|
|
|
|
Hola !
As I promised you I Wrote the article about Streams and Pictures and ActiveX, you can check it out in:
http://www.codeproject.com/useritems/PictureTransfer.asp
The bad thing... something went wrong with the submission wizard and the Picture and the zip with the source is not there ( I sent one e-mail to chris with the files, let´s hope he fixes it).
Bye !
Braulio
|
|
|
|
|
Hello,
I use the function PolyBezier(), so I have a curve composed of "n" Bezier Curves , but I don't know how to get the y coordinate of my curve giving the x coordinate. Is there a solution ?
Thanks
|
|
|
|
|
The curve is made up of connecting Bezier segments, each depending on two end points P0 and P3 and two so-called control points P1 and P2. Points in the segment are given by
x(k) = (1-k)3x0 + 3k(1-k)2x1 + 3k2(1-k)x2 + k3x3,
y(k) = (1-k)3y0 + 3k(1-k)2y1 + 3k2(1-k)y2 + k3y3,
where k ranges between 0 and 1.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi,
Can anyone tell me how to set the title of the main window in a SDI Doc/View Architecture app. Do i can totally replace 'untitled - Name Of App' ?
Regards
Richard
|
|
|
|
|
You can try to use CWnd::SetWindowText()
Hoope it help
Bye,
BogdanO
...the night is long ... but not long enought to do some real coding ...
|
|
|
|
|
The standard way of doing this is using <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cdocument.3a3a.settitle.asp">CDocument::SetTitle</a> .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|