View Full Version : How to use scrrun.dll in VisualC++?
JohnWen604
07-08-2005, 02:06 AM
Hello,
I know how to use scrrun.dll in Visual Basic. But, how to use scrrun.dll in Visual C++? Also type "#pragma comment(lib, "scrrun")"? Note that there is no such scrrun.lib in the computer!! There must be error in doing it. I have tried it before.......
In addition, how should I use the method OpenTextFile("easy.txt") in the object "FileSystemObject" within scrrun.dll? Could you write the corresponding code?
Thank you.
JOhn Wen604
8-July-2005
f5hacka
07-08-2005, 02:50 PM
Personally, and especially if you're new to C++, I'd suggest heading over to cplusplus.com (http://www.cplusplus.com) and reading the references to the C standard library for basic file I/O. Its a great site for learning how to use the libraries and just for reference. Assuming you're trying to do some file I/O.... :)
JohnWen604
07-08-2005, 07:58 PM
Personally, and especially if you're new to C++, I'd suggest heading over to cplusplus.com (http://www.cplusplus.com) and reading the references to the C standard library for basic file I/O. Its a great site for learning how to use the libraries and just for reference. Assuming you're trying to do some file I/O.... :)
Hi,
To tell you somethiing, I am now testing how to use dll from Visual C++, such as scrrun.dll or dll developed by me. I don't think the web sites that you provided can answer my question about dll. I ask question when I have a real need. So can any one of you be kind to answer my question?
The question is : " how to use scrrun.dll in Visual C++?" And, how to use the methods such as opentextfile or createtextfile?how to use the object such as FileSystemObject or TextStream or Dictionary?
I believe all of those are COM/ActiveX components. It's something of a challenge to do ActiveX in C++, even if you use MFC. I suggest finding a good article/tutorial/book on the subject. You can also refer to MSDN.
You basically have to use wrapper classes for the component. To generate them, do this:
1. Start Ole/Com Object Viewer (should be in your Tools start menu folder), go to File->View TypeLib and choose COM DLL you want to use
2. TypeLib viewer window will open on top (modal). Click the save button and save the IDL definition into an IDL file.
3. Run Microsoft IDL Compiler (located in your C++ program folder) from this command line:
midl /Oicf /W1 /Zp8 /h header_file.h /iid c_file.c idl_file.idl
Where header_file.h is the name of header file that you want to generate for DLL's com interfaces, c_file.c is the C file you want to generate, and idl_file.idl is the name of idl file you saved in step 2.
Once the IDL file has been created, open the IDL file in the editor and look for a series of enum typedefs which define the constants:
typedef [public]
__MIDL___MIDL_itf_scrrun_0094_0002 SpecialFolderConst;
typedef enum {
WindowsFolder = 0,
SystemFolder = 1,
TemporaryFolder = 2
} __MIDL___MIDL_itf_scrrun_0094_0002;
These declarations are a side-effect of how the COM Object Viewer generates the IDL file and it needs to be cleaned up a bit so that the MIDL compiler generates the correct header file. Remove the typedef [public] section before each typedef enum section in the file. In other words, you would want to remove each section that looks like:
typedef [public]
__MIDL___MIDL_itf_scrrun_0094_0002 SpecialFolderConst;
The actual enum typedefs can stay in the IDL so that they're included in the header file and can be used by the application. Note that if these extraneous typedefs aren't removed, the MIDL compiler will generate duplicate enums in the header file and will cause compiler errors.
Then in your program, #include the h file and add both to the project. Now you can use COM functions and the code in generated classes to use the COMponent.
=========================
Some of the above was taken from
http://www.catalyst.com/support/help/internetmail/index.html?page=html%2Fmail%2Fguide%2Fobjectmodel.html
Look at it as an example of how to do what you need to do.
Also see this link. It is similiar to the last, but explains stuff better:
http://www.codeproject.com/com/vb_from_vc.asp#xx803648xx
JohnWen604
07-15-2005, 11:54 PM
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
Powered by: vBulletin v3.8.4