| James's profileJames McCaffreyBlogLists | Help |
|
April 26 Installing Visual Studio 2005 and SQL Server 2005 on Windows VistaI installed Visual Studio 2005 (Team System) and SQL Server 2005 (Standard Edition) on a machine running Windows Vista (Business Edition) today. The process was a little bit cruder than what I've become accustomed to with installing software on Windows XP and Windows Server 2003. But in hindsight, that makes sense -- Vista is an OS and so no existing programs were originally designed for Vista. Anyway, here are some of the glitches I ran into and how I got around them. First, installing Visual Studio 2005 was not too difficult. The main issue was being aware that after installing Visual Studio 2005, you need to immediately install Visual Studio 2005 Service Pack 1, and then install Visual Studio Service Pack 1 Upgrade for Vista. The only minor irritation here is that VS2005 SP1 is 400+ MB in size (VS2005 SP1 Upgrade for Vista is 30MB). I easily found both these downloads from Microsoft by doing a Web search for "Visual Studio SP1".
After a reboot and verifying that Visual Studio was successfully installed, I had a lot more trouble installing SQL Server 2005 on Vista. My real problem was that I did not first prepare my machine (before attempting the SQL Server install) by configuring IIS 6. So, halfway through the SQL install, I got an error message, "Microsoft Internet Information Services (IIS) is either not installed or is disabled. IIS is required by some SQL Server features. Without IIS, some SQL Server features will not be available for installation. To install all SQL Server features, install IIS from Add or Remove Programs in Control Panel or enable the IIS service through the Control Panel if it is already installed, and then run SQL Server Setup again."
"That's odd", I thought -- I knew my machine had IIS installed and configured because I had earlier created a dummy test page hello.html, saved it at C:\Inetpub\wwwroot, and was able to access it in IE by navigating to http://localhost/hello.html. So I cancelled the SQL install. Eventually I realized that even though IIS was installed, it was not configured properly. OK, so let's go to Control Panel | Add or Remove Programs | "Add/Remove Windows Components" to configure IIS. Oops, it's not there -- where did it go on Vista? Dang. It is now at Control Panel | Programs and Features | "Turn Windows features on or off" link. OK, found it. Now which IIS settings do I need to configure? Well, amazingly, I never did find a Microsoft site that listed exactly which IIS features I needed. Double dang. So, I enabled all IIS settings.
OK, now that IIS has been 100% configured I should be able to restart and complete the SQL install, right? Oops. Again, halfway through the install I got the exact same IIS error. What the hey? OK, cancel the SQL Server install again. Well, to make a long story short, when I cancelled the initial SQL Server installation, I got into a kind of zombie state. The fix was to go to Control Panel | Programs and Features and then uninstall "Microsoft SQL Server Native Client" and "Microsoft SQL Server Setup Support Files". Now, I restarted the install and everything worked fine. Sort of.
After finishing the install, I downloaded SQL Server 2005 Service Pack 2 (at about 300MB), and ran it. Near the end of the SP2 install process I got a message saying that by default, no regular Windows Vista Administrator group user accounts are granted permission to connect to SQL Server, and do I want to run the SQL Server Provisioning Tool for Vista. Well sure, I guess I'd like to be able to actually connect to SQL (begin/end sarcasm). A nice GUI popped up with my user account, I added the account to the SQL SysAdmin role and clicked OK and . . . it errored out. I don't remember what the error message was unfortunately but it was something about ADO.NET. OK, finish SQL install and reboot. Launch SQL Server Management Studio and try to connect to my new SQL instance. Fail. Dang. OK, let's try the Provisioning Tool again. Where the @#$! is it? Cleverly tucked away at C:\Program Files \Microsoft SQL Server\90\Shared and named SqlProv.exe. Well, I re-ran the tool, and this time I successfully added myself to the SQL SysAdmin role, and was able to connect to SQL using Management Studio.
Moral of the story: Vista is a new operating system and you're going to have installation issues like these until programs written for, and developed on, Vista become available. April 21 Calling COM Objects - Techniques 2 and 3 of 5In a recent series of blog posts, I described how to write a custom COM object using C++ and the ATL wizard in Visual Studio 2005. My COM component is named MyMathLib and contains a class ("coclass") named MyFuncs which in turn holds two methods -- Sum(x,y) and Product(x,y) which just return the sum and product (result of multiplication) of two long ints. Let's suppose that my COM component project is saved in a root directory arbitrarily named VS223. In my last blog entry I showed how to called the classic COM object using native Win32 C++ code -- and it was ugly -- very ugly. In this entry I'll demonstrate calling the COM object using JavaScript and VBScript. To use JavaScript, simply launch an instance of notepad and type this code: // test.js Save as file test.js and then execute from a command shell by typing: C:\VS223\YourName> cscript test.js Much easier than using C++. This is one of the key points of COM objects: they can be called by many different languages. Here we use the JavaScript ActiveXObject() method to instantiate the COM object using its ProgID. Using VBScript is very similar. Launch an instance of notepad and type this code: 'file: test.vbs Save as file test.vbs and then execute from a command line by typing: C:\VS223\YourName> cscript test.vbs The main difference, apart from syntax, is that VBScript uses the CreateObject() method. April 15 Calling COM Objects - Technique 1 of 5In a recent series of blog posts, I described how to write a custom COM object using C++ and the ATL wizard in Visual Studio 2005. (See Introduction to COM - Step 0 of 12).My COM component is named MyMathLib and contains a class ("coclass") named MyFuncs which in turn holds two methods -- Sum(x,y) and Product(x,y) which just return the sum and product (result of multiplication) of two long ints. Let's suppose that my COM component project is saved in a root directory arbitrarily named VS223. In this blog entry, I will show you how to call the COM object from a classic C++ program. Launch a new instance of Visual Studio 2005. Do a File | New | Project. Choose Win32 -> Win32 Console Application. Save at any convenient location (say, C:\VS223) with any convenient name (say, Test). Accept the default Application Settings. In the Test.cpp source, blast away the VS-generated code and replace with this:
#include "stdafx.h"
#include <stdio.h> #include "..\MyMathLib\MyMathLib.h" #include "..\MyMathLib\MyMathLib_i.c" int main(int argc, char* argv[])
{ CoInitialize(NULL); HRESULT hr = S_FALSE; IMyFuncs* ptr; long Answer; CoCreateInstance(CLSID_MyFuncs, NULL, CLSCTX_INPROC_SERVER, IID_IMyFuncs, (void**)&ptr); hr = ptr->Sum(5,4, &Answer); printf("\nFive plus four is %d \n", Answer); CoUninitialize(); return 0; } Notice the #includes refer to the COM File name but inside the code you refer to the Class name. Build the project, then launch a command shell, navigate to the Test.exe file and execute. CoInitialize() initializes the COM library on the current thread of execution. The ptr variable is a pointer to the COM interface. The call to CoCreateInstance() does all the messy work of instantiating a COM object and associating the object with pointer ptr. We use the arrow notation to access the Sum() method. All in all, extremely ugly and you can see why Microsoft created .NET to eliminate having to use COM for simple applications programs.
April 07 Introduction to COM: A Simple Step-By-Step ExampleI have just posted a series of blog entries which show a step-by-step process of creating a COM component. COM (Component Object Model) is an extremely complex technology which is designed to create a compnent which can be used by multiple programming languages. COM compnents are usually created using the C++ language. Creating a COM component is so difficult that Microsoft created something called ATL (Active Template Library) which you can think of as a super-wizard to help. Even the terminiology is complex. COM is a blanket term for many sub-technologies such as OLE, ActiveX, DCOM, and COM+. Each of these sub-technologies has sub-sub technologies such as ActiveX controls. The purpose of my series of blog entries is to walk you through the creation of a very simple COM component which has a simple Sum(x,y) method which just adds two numbers. After you can create a simple COM component you are in a much better position to understand the tons of documentation on the topic. You can view the first step in the process of writing a COM object at Start: Step 0 of 12. Introduction to COM - Step 12 of 1212. On the main menu, do a Build | Build Solution and watch the Output window to verify that your classic COM object builds correctly. You should also go to Windows Explorer and verify that file MyMathLib.dll has been created. When you use Visual Studio to build a COM component, the component is automatically registered on your machine and is ready to use. You can verify this by searching your system registry for the COM component's ProgID, which is MyMathLib.MyFuncs in this case. If you intend to use your COM component on a different machine, after you copy the DLL, you must register the component using the regsvr32.exe utility program. In my next series of blog entries, I will show you 5 different ways to call the MyFuncs component. Introduction to COM - Step 11 of 1211. Inside the Sum definition, add this code:
HRESULT hr = S_OK; *pRes = x + y; return hr;
over the existing dummy "return S_OK" statement. This code makes no attempt to check input parameters and is very crude. Remember that because COM methods return HRESULT values for error-checking, we must store our sum into a pointer (*pRes). I used pRes to stand for "pointer to result".
Introduction to COM - Step 10 of 1210. In Solution Explorer, switch to the default Solution Explorer tab, then double-click on the MyFuncs.cpp file to go to its code. We are now ready to write some code.
Introduction to COM - Step 9 of 129. You will be at the Add Method wizard. Be very careful here. For the "Method Name" field, type Sum. You will add three parameters. First, check the "in" attribute, then select LONG parameter type, then type "x" for the "Parameter Name", then click Add. Second, check the "in" attribute, then select LONG parameter type, then type "y" for the "Parameter Name", then click Add. Third, for the parameter type select *LONG, then for the parameter attributes select retval (which will automatically select "out" also), then type pRes for the parameter name. (See screenshot below). Click Add. Double-check everything, then click the Next button. COM methods return something called a HRESULT -- typically used for error-checking -- so the functional return value (in this case the sum of two long integers) must be stored in an out parameter. Introduction to COM - Step 8 of 128. In the Solution Explorer window, select the Class View tab. Right-click on the IMyFuncs interface and select Add | Method. Interfaces are the mechanism through which COM components expose their functionality. Interfaces are a very complex subject but here we don't need to undersand much about them -- just think of an interface as something to hold one or more methods. Introduction to COM - Step 7 of 127. You will see the Options dialog -- all of these are OK so click Finish. Threading Models is an advanced topic. A Dual interface allows our eventual COM component to be called from scriptinmg languages such as VBScript and PowerShell as well as C++. Introduction to COM - Step 6 of 126. In the "Short Name" field, type MyFuncs -- all the other names will be filled in automatically. Take particular note of the ProgID name -- this is how you will access the COM object from scripting languages. Click Next. Yikes. If we weren't using ATL we'd have to create all these files manually. Introduction to COM - Step 5 of 125. In the Categories pane, select ATL. In the Templates pane, select "ATL Simple Object". Then click the Add button. The term "COM" is often used as a blanket term for specific technologies including OLE, OLE Automation, ActiveX, COM+ and DCOM. Each of these sub-technologies has many sub-sub-technologies such as ActiveX Controls. Here we want a basic COM component. Introduction to COM - Step 4 of 124. In Solution Explorer, right-click on the project name and select Add | Class to add a class. If you refer to the picture in Step 0 of this blog series, you'll see that a COM component holds one or more classes which in turn hold one or more methods. Here we are going to add a single class. Introduction to COM - Step 3 of 123. Now you will see Application Settings. Leave the defaults as shown and click Finish. We are doing the most basic kind of a COM component which is housed inside a DLL. The "attributed" tag would allow properties but that's the subject of another blog entry. Introduction to COM - Step 2 of 122. You will see a Welcome screen; simply click Next. ATL (Active Template Library) is a somewhat misleading title. ATL can be used as a library of various data structures but here we are using ATL as a wizard to help with the creation of a COM component. Introduction to COM - Step 1 of 121. Launch Visual Studio 2005. Select File | New | Project. Expand the Visual C++ Project Types and select ATL. In the Templates area, select ATL Project. In the Location field, type C:\VS223 (VS223 is arbitrary and corresponds to a training class at Volt/Microsoft). In the Name field, enter MyMathLib. Make sure the "Create directory for solution" checkbox is not checked. Click OK. You can think of ATL (Active Template Library) as a super-wizard which will help you create COM code. See the image below.
Introduction to COM - Step 0 of 12I was looking at classic COM (Component Object Model) technology recently and could not find a simple step-by-step reference. So, over the next 12 blog entries I will walk you through the creation of a simple COM component using Visual Studio 2005. We will create a COM component named MyFuncs which holds a Sum(x,y) method that simply adds two integers, and which is housed inside a DLL named MyMathLib.dll file. See the diagram below. COM is an insanely complex topic and the point of my blogs is simply to get you over the initial COM hurdle so you can understand the many references available to you. (Wikipedia has a good entry on COM.) After I finish posting the 12 blogs on how to create COM, I will post 5 blog entries showing you different ways to use the COM component we create here.
|
|
|