|
FILE is a structure and you can use it to open,read, or write files with it.You said you have a data file and you want to read it from your ACtiveX.
This is an example from MSDN:
FILE *stream, *stream2;
void main( void )
{
int numclosed;
if( (stream = fopen( "data", "r" )) == NULL )
printf( "The file 'data' was not opened\n" );
else
printf( "The file 'data' was opened\n" );
if( (stream2 = fopen( "data2", "w+" )) == NULL )
printf( "The file 'data2' was not opened\n" );
else
printf( "The file 'data2' was opened\n" );
if( fclose( stream ) )
printf( "The file 'data' was not closed\n" );
numclosed = _fcloseall( );
printf( "Number of files closed by _fcloseall: %u\n", numclosed );
}
Is that what you want or I misunderstood your problem?
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
|
|
|
|
|
I guess I wasn't clear, I do know how to open close and read files. My problem is getting the file. If the ActiveX control is embedded in a webpage and the file is on the server with that page how do I open that file? Basically what I am trying to setup is something like Macromedia Flash.
|
|
|
|
|
Could you tell me how to Use Com Event in VC6.0?
For example:
In my program,I want to use 'Shell.Explorer'(Web Broswer),but how can I get its Event(NewWindow2,NavigateComplete2...) by MFC or SDK?
Thanks!
|
|
|
|
|
MFC:
First add it to your dialog, form,or anywhere you want,go to class wizard,select the class you put it there,then find the
ID of your component in left list box and select it,at this point you can see the event of your component inthe right list box and you can add it.
For SDK:
I never test it but just guess,you can see in your MFC, and see what codes it add to your class you do the same in your SDK projetc
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
|
|
|
|
|
Take a look at < a href =www.voksoe.dk> this website for lots of IE toolband, explorer band samples that connects and uses WebBrowser events. Mostly these are ATL projects, but you'd get the drift.
#define MOSTLY_LEAN_AND_MEAN
|
|
|
|
|
i.e. www.viksoe.dk. sorry.
#define MOSTLY_LEAN_AND_MEAN
|
|
|
|
|
can any body tell me what's going on
when i compile my project with MVC++ 6.0 everything is fine
but when try it with MSVC++ 5.0 i get the next error and i rely have to get it working with 5.0
:
main.obj : error LNK2001: unresolved external symbol "long __stdcall ATL::AtlModuleInit(struct ATL::_ATL_MODULE *,struct ATL::_ATL_OBJMAP_ENTRY *,void *)" (?AtlModuleInit@ATL@@YGJPAU_ATL_MODULE@1@PAU_ATL_OBJMAP_ENTRY@1@PAX@Z)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall ATL::CComTypeInfoHolder::AddRef(void)" (?AddRef@CComTypeInfoHolder@ATL@@QAEXXZ)
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall ATL::CComTypeInfoHolder::Release(void)" (?Release@CComTypeInfoHolder@ATL@@QAEXXZ)
main.obj : error LNK2001: unresolved external symbol "public: long __thiscall ATL::CComTypeInfoHolder::GetTypeInfo(unsigned int,unsigned long,struct ITypeInfo * *)" (?GetTypeInfo@CComTypeInfoHolder@ATL@@QAEJIKPAPAUITypeInfo@@@Z)
main.obj : error LNK2001: unresolved external symbol "public: long __thiscall ATL::CComTypeInfoHolder::GetIDsOfNames(struct _GUID const &,unsigned short * *,unsigned int,unsigned long,long *)" (?GetIDsOfNames@CComTypeInfoHolder@ATL@@QAEJABU_GUID@@PA
PAGIKPAJ@Z)
main.obj : error LNK2001: unresolved external symbol "public: long __thiscall ATL::CComTypeInfoHolder::Invoke(struct IDispatch *,long,struct _GUID const &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,
unsigned int *)" (?Invoke@CComTypeInfoHolder@ATL@@QAEJPAUIDispatch@@JABU_GUID@@KGPAUtagDISPPARAMS@@PAUtagVARIANT@@PAUtagEXCEPINFO@@PAI@Z)
main.obj : error LNK2001: unresolved external symbol "long __stdcall ATL::AtlInternalQueryInterface(void *,struct ATL::_ATL_INTMAP_ENTRY const *,struct _GUID const &,void * *)" (?AtlInternalQueryInterface@ATL@@YGJPAXPBU_ATL_INTMAP_ENTRY@1@ABU_GUID@@
PAPAX@Z)
|
|
|
|
|
One possibilty:
Link error 2001 happends when you use some function from a dll but you did not add that library to that project,so check if you use specific dll and if you add it to your project setting.
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
|
|
|
|
|
Hello. I hope someone can help me.
what does this error mean and how can solve this:
[Linker Error] Unresolved external '__stdcall AtlModuleInit(_ATL_MODULE *, _ATL_OBJMAP_ENTRY *, void *)' referenced from C:\HW\TEST\TEST2\UNIT1.OBJ.
it is a borland C++ builder 4 compiler.
|
|
|
|
|
Hey all,
I have just started learning COM, and have been following the lab exercises from one of the commerical books. I am in the process of learning how to use dllhost.exe to host my Dll server( Originally, I had developed my server as an in process server without using ATL. ) The book told me to add the AppID to the registry by selecting the "Use Surrogate Process" in OLE/COM viewer. I did exactly that. However, when I tried to run the client, I got an error message that said: "No such interface supported".
The code that generated this error message is as follows:
IMyinterfacePtr p;
p.CreateInstance( __uuidof( CoMyClass ), NULL, CLSCTX_LOCAL_SERVER );
At first, I was very puzzled, but when I went back and looked at my object under the OLE/COM viewer, I can only see the IUnknown interface being exposed, but not IMyinterface.
Does anybody know what's happening? If so, what is the solution to the problem?
Your help is really apprepriate, since I am in this dark hole right now not being able to solve it.
Sunny
|
|
|
|
|
You have the IMyinterface declared inside the CoClass definition on the idl file ?
Joao Vaz
|
|
|
|
|
Yes, I have IMyinterface declared inside the CoClass definition. In fact, my idl file is shown below, using real variable names rather than IMyinterface:
//----------------------------------
/*
This IDL file describes all the COM-isms
contained in the CarServer Library
*/
// Bring in core IDL files.
import "oaidl.idl";
// IStats
[object, uuid(A533DA31-D372-11d2-B8CF-0020781238D4),
helpstring("Get info about this car")]
interface IStats : IUnknown
{
HRESULT DisplayStats();
HRESULT GetPetName([out, retval] BSTR* petName);
};
// IEngine
[object, uuid(A533DA30-D372-11d2-B8CF-0020781238D4),
helpstring("Rev your car & slow it down")]
interface IEngine : IUnknown
{
HRESULT SpeedUp();
HRESULT GetMaxSpeed ([out, retval] int* maxSpeed);
HRESULT GetCurSpeed ([out, retval] int* curSpeed);
};
// ICreateCar
[object, uuid(A533DA32-D372-11d2-B8CF-0020781238D4),
helpstring("This lets you create a car")]
interface ICreateCar : IUnknown
{
HRESULT SetPetName([in]BSTR petName);
HRESULT SetMaxSpeed([in]int maxSp);
};
[uuid(82BA20D1-F07D-11d2-B8E0-0020781238D4), version(1.0),
helpstring("CoCar server with TypeLib")]
library CarServer
{
importlib("stdole32.tlb");
[uuid(82BA20D2-F07D-11d2-B8E0-0020781238D4)]
coclass CoCar
{
[default] interface ICreateCar;
interface IStats;
interface IEngine;
};
};
//-------------------------------- END
Also, since I am talk to an out-of-process server( actually, to a dll hosted by dllhost.exe), do I need to include the proxies/stubs in my build workspace? I currently don't have them included. Is this the reason why it failed to run?
Sunny
|
|
|
|
|
Sunny, you updated the reg ?
After adding a AppId in the HKCR, you also changed the HKCR\CLSID of the CoClass to point to the updated AppId ?
Also you don't need to include the proxy/stub because you're using type library marshaling.
I also see that you're are using the best book to learn atl ... Developer's workshop to COM and ATL 3.0 by Andrew Troelsen
Joao Vaz
|
|
|
|
|
In an ATL ClassWizard generated Control that is used in VB, how do you create a hidden window that can fire events for your worker thread? I've been trying to do this using a GlobalInterfaceTable, and firing events work, but not when you call WaitForSingleObject() to wait for a request to InternetReadFileEx() to finish (cuz it's in VB and that locks up the program until it's done) How is that possible with an already made class? I tried sticking CWinImpl in the class declaration, but it contradicts CComControl so I cant use it. Is there a class that I can call dynamically or a class that doesnt have to have a Type specifier aka:"CWinImpl<cmyobject>" <-- which gives me the error cuz it has CComControl in the dec. any Pointers, Tips, or Hints?
~Timothy T. Rymer
www.digipen.edu
tim.xpertz.com
|
|
|
|
|
Tim, see my aswers bellow , the anonymous and the other
Joao Vaz
|
|
|
|
|
Hey I've been working on an ATL Object that uses Asynchronous WinInet API's, which end up getting used up to about 20 at a time, but i'm only really testing at 2 right now, which has the same problem:
The program that uses more than one of these objects at a time locks up when waiting for data from the callback function. It uses little or no processor power, but sits there and stays locked until it gets the data, then finally moves on. (the OS is fine and switching windows and hitting the Start buttons all work fine, so it's just the program)
*NOTE: I noticed how MSDN did it
(ARTICLE:Calling Win32 Internet Functions Asynchronously),
and it seemed like a great idea to create the worker thread inside of the callback function, but for some reason I couldnt get my ATL object to work (i think it may have to do with not having experience first time around and not being smart and firing events from that callback thread) either way, it's not the way i'm doing it and i'm not changing it. unless you're "for sure" that it can work easily.
HERE'S HOW I DID IT:
1. I fire events from the worker thread by using IGlobalInterfaceTable and cookies. (the App is in VB - no changing that either)
2. More importantly, in my worker thread, I call WaitForSingleObject() and I wait for the event that i had created and a bool member variable that is changed (because it seems like sometimes it will pick up the other ATL objects' SetEvent() calls so i just make sure that it is that object's Event that was set. Now in MSDN's version, you dont have to do call WaitForSingleObject() because it starts the thread when it has the Url's HINTERNET handle. Right now that's not a big deal at all, cuz when it's waiting to connect, i can move the program's window around and it hasnt locked up.
OK HERE'S THE BAD PART:
When I Call InternetReadFileEx() I check for ERROR_IO_PENDING of course, and when i get that, I call WaitForSingleObject() and wait for the INTERNET_STATUS_REQUEST_COMPLETE status. IT LOCKS UP THE PROGRAM NOW. This is all in the worker thread! What is the deal? No CPU Usage And Yet, NO CONTROL!
And if that ever gets figured out, i have yet to find out how to properly kill the internet APIs and after that, do another address with the same object.
And in the callback function, what is dwInternetStatus = 320, 321???? I havent found a thing on what that might actually be! it's not in MSDN, and i dont have a clue what it is, but it's actually a good value. but i sure dont know though.
I just really need some good implementation advise. Any advise will be great, and being this is my first real job, i do not want to disappoint, so please help.
~Timothy T. Rymer
www.digipen.edu
tim.xpertz.com
|
|
|
|
|
Hum, you could try this link
http://www.codeproject.com/useritems/asyncwininet.asp#xx84731xx
Also you could check chapter 9 source code of the
Essential Wininet book, a good book that i used to program wininet and com winnet applications, and the chapter 10 that deals with http wininet com components, this book was a life savier for me in the past
,
Ah , and because your app is in VB and since Vb doesn't support multithreading, in this case i think they recommend 2 ways to solve this problem, and one, the best one(the one that i used )is to create a message pump in the main thread that catches the message of the worker thread and then dispatches the event in the callback that is on the main thread to the vb app, check for "events and atl and vb" in msdn for a more correct explanation.
Hope this helps ,
Joao Vaz
|
|
|
|
|
Here's the thing with the message pump, I dont really know how to do that coming from an ATL object... do you see where i'm coming from? I've heard that a bunch but i've always stayed away from it because i didnt know how to make one (that's what i used IGlobalInterfaceTable which worked with Firing Events, but obviously is not working with WaitForSingleObject() now if you have an example.... then that might be a different story... for me i wouldnt know where to start.
~Timothy T. Rymer
www.digipen.edu
tim.xpertz.com
|
|
|
|
|
|
Ok, I guess i'm just going to have a class that is derived from CWnd, do I HAVE to use CWnd? I've seen all those articles before, of course they dont make much sense when you havent actually done whatever they are saying to do, but I guess i'm just expecting to see an example of a normal CreateWindow function and then the message loop function that would fire the event after each PostMessage() not just a ctor to CWnd... but i'll try my best, thanks for the help, I just wish I had done this once before cause it always makes sense the 2nd time around...
~Timothy T. Rymer
www.digipen.edu
tim.xpertz.com
|
|
|
|
|
Tim, i thought that your object is in ATL ,
if so you must add the public CWindowImpl<cmyclass> to your inheritance chain, CWnd is for MFC controls, not ATL !
Do a step by step procedure of the kb: Q196026 http://support.microsoft.com/default.aspx?scid=kb;PT;q196026
Happy coding, and also don't forget to check Essential Wininet sourcecode for proper asynch behavoir.
Regarsds,
Joao Vaz
|
|
|
|
|
I didnt know that... its tough trying to pick out the important parts, especially when you havent done it before. I'll put CWindowImpl in my obj and try to use it. Thanks!
~Timothy T. Rymer
www.digipen.edu
tim.xpertz.com
|
|
|
|
|
1. When I throw CWinImpl<myobject>, into the header, It gives me an error about already having CComControl in my thing as well. What should I do? Should I just make a variable of CWinImpl in my ATL Class?
and if that works, how do I make it windowless? do i just not set a STYLE when I create the window? or do i just make a DialogBox and call ShowWindow(WS_HIDE) or something?
I dont want anything showing up of course, nothing in the background, etc. Any Tips?
~Timothy T. Rymer
www.digipen.edu
tim.xpertz.com
|
|
|
|
|
From the article
Steps to Reproduce Behavior
The following example first creates an ATL project, then a Visual Basic 6.0 project. It then uses these to demonstrate the proper way to have a secondary thread request that the primary thread fire an event.
Steps to Create an ATL Project with Visual C++
Create a new ATL COM AppWizard Project named MyAtlDll and keep the default settings.
In the class view, right-click the project name and select New ATL Object. Select Simple Object in the displayed dialog box and click Next. Type in "MyAtl" as the C++ short name. Click the Attribute tab and select Support Connection Points. Click OK and a new ATL object is added.
In the class view, right-click the IMyAtl and choose Add Method. Type "InitTask" in the Method Name text box and "[in] long number" in the parameters text box. Click OK.
In the class view, right-click _IMyAtlEvents and select Add Method. Select "void" from return type drop-down list box. Type "TaskFinished" in the Method Name text box and "[in] long result" in the parameters text box. Click OK.
In the class view, right-click CMyAtl and choose Add member variable. Type "long" in the variable type text box and "m_number" in the variable name text box.
Build the project to generate the type library needed for step 10.
In the class view, expand and double-click CMyAtl -> IMyAtl -> InitTask. Edit the InitTask function to make it appear as follows:
STDMETHODIMP CMyAtl::InitTask(long number)
{
HANDLE hThrd;
DWORD tid;
m_number = number;
if((hThrd = CreateThread(
0,
0,
(LPTHREAD_START_ROUTINE)justDoIt,
(void *)this,
0,
&tid)) == NULL)
{
//error handling here
}
CloseHandle(hThrd);
return S_OK;
}
Add the following code to the MyAtl.cpp file:
DWORD WINAPI justDoIt(LPVOID lpParameter)
{
CMyAtl *myAtl = (CMyAtl*)lpParameter;
long result;
for (int i = 1; i <= myAtl->m_number; ++i)
result = i * 2;
myAtl->Fire_TaskFinished(result);
return 0;
}
Add the following code right above the line "#endif //__MYATL_H_" in MyAtl.h file:
DWORD WINAPI justDoIt(LPVOID lpParameter);
In the class view, right-click CMyAtl and select Implement Connection Point. Select _IMyAt-Events in the displayed dialog box. Click OK.
Build the ATL project and the control will be registered automatically.
Steps to Create the Visual Basic 6.0 Project
Create a new Standard EXE project. Form1 is created by default.
Choose References from the Project menu, select "MyAtlDll 1.0 Type library," and click OK.
Add a CommandButton to the form and keep the default name (command1).
Add the following code to the code window of form1:
Option Explicit
Private WithEvents vbATL As MYATLDLLLib.MyAtl
Private Sub Command1_Click()
vbATL.InitTask 11111
End Sub
Private Sub Form_Load()
Set vbATL = New MYATLDLLLib.MyAtl
End Sub
Private Sub vbATL_TaskFinished(ByVal result As Long)
MsgBox result
End Sub
Press the F5 key to run the project. Click Command1 and you will get 22222 in a message box.
Build the project to be an EXE and run the EXE outside the IDE. You will get an error message when you click the CommandButton.
Note that it may work sometimes, but it does not work consistently.
To fix the problem in this specific sample, you need to derive the CMyAtl from CWindowImpl, and add a message map. Make sure the window is hidden. Now, instead of firing an event from the secondary thread, you can post a message to the main thread, and fire the event in the message handler.
Step by Step Example
Using the ATL project created in the steps above, add the following line:
#include <atlwin.h>
after the line:
#define _MYATL_H
in the MyAtl.h file.
Add the line:
#define WM_TASK_FINISH (WM_USER + 101)
before the line:
class ATL_NO_VTABLE CMyAtl :
in the MyAtl.h file.
Add CWindowImpl to one of the parent classes of CMyAtl by adding the following line:
public CWindowImpl<CMyAtl>,
right after the line:
class ATL_NO_VTABLE CMyAtl :
in the file MyAtl.h.
Add the following code to the CMyAtl definition part of the MyAtl.h file:
public:
DECLARE_WND_CLASS("MyAtl")
BEGIN_MSG_MAP(CMyAtl)
MESSAGE_HANDLER(WM_TASK_FINISH, OnTaskFinished)
END_MSG_MAP()
public:
LRESULT OnTaskFinished(UINT uMsg, WPARAM wParam,
LPARAM lParam, BOOL& bHandled)
{
Fire_TaskFinished((long)wParam);
return 0;
}
HRESULT FinalConstruct()
{
RECT rect;
rect.left=0;
rect.right=100;
rect.top=0;
rect.bottom=100;
HWND hwnd = Create( NULL, rect, "MyAtlWindow", WS_POPUP);
if (hwnd)
return S_OK;
else
return HRESULT_FROM_WIN32(GetLastError());
}
void FinalRelease()
{
if (m_hWnd != NULL)
DestroyWindow();
}
Change the following line:
myAtl->Fire_TaskFinished(result);
in the function
DWORD WINAPI justDoIt(LPVOID lpParameter)
in the file MyAtl.cpp, to be:
myAtl->PostMessage(WM_TASK_FINISH,result,0);
Rebuild the ATL project.
Run the Visual Basic project from the IDE and as an EXE. Note that the event fires just fine either way.
|
|
|
|
|
The CComControl class derives by default from CWindowImpl, so the error...
About the windowless aspect, i think that by default CComControl window is windowless, so no reason to worry, i think
If isn't windowless, then put this in the private parte of your class:
unsigned m_bWndLess:1;
, this variable is a member of a union declared in
CComControlBase, a base class of CComControl, so it's necessary to declare it in the current class, but i think you wouldn't need this ...
Cheers;
Joao Vaz
|
|
|
|
|