Also see this link. It is similiar to the last, but explains stuff better:
http://www.codeproject.com/com/vb_from_vc.asp#xx803648xx
Hello,
I have followed your advice, but I got one compile error message which is
"error C2065: IID_FileSystemObject' : undeclared identifier" :rolleyes:
Why I cannot use IID_FileSystemObject? I just copied the code from http://www.codeproject.com/com/vb_from_vc.asp#xx803648xx
:huh: Note that when I used "midl" compiler to compile the .idl file into .c and .h file, I got some error message which is " expecting a type specification near "specialFolderConst", even though I have removed all typedef [public] statements! :huh:
:huh: Then, I just simply deleted all statements which alerted me as an error until I got no error message. :huh: For example, if line 281 has an error then I just delete the statement on line 281. I think I did wrong, but can you tell me what to do except doing what I have done? Please right me if I really did wrong!(I mean delete the error lines...)
So how can I succesfully use the "FileSystemObject" object from VC++?
My VC++ code is as follows:
///////////////////////////////////////////////////////////////////////////////
#include "helloScrrunInterface.h"
#include <iostream.h>
#include <comdef.h>
void main()
{
//FileSystemObject *A = new FileSystemObject();
FileSystemObject *A;
Dictionary *X;
HRESULT hr;
hr = CoInitialize(0);
// Use the SUCCEEDED macro and see if we can get a pointer
// to the interface
hr = CoCreateInstance( CLSID_FileSystemObject,
NULL,
CLSCTX_INPROC_SERVER,
IID_FileSystemObject,
(void**) &A);
cout<<A->opentextfile("TestScrrun.cpp").ReadAll();
}
///////////////////////////////////////////////////////////////////////////
The next question is why I cannot write "FileSystemObject *A = new FileSystemObject();" VB's new can import the dll when one of the classes within that dll is first used. Then why VC++'s new cannot do the same? I think the reason is that VB's new's implementation is much more complex than VC++'s new 's implementation, am I right? VC++'s new is only used with C++'s classes, not with classes in the COM/ActiveX DLL. Am I right?
Last question is that when will I get the hr failure?(HRESULT hr). I found out that when I used the ActiveXDLL developed using VB, all the time it(hr) fails after it succeed once! Why?
JohnWen604
16-July-2005