一直在使用VC6+MOIMS开发CGI模式的WebGIS系统,但却始终不知道在vc6中如何使用IMSUtil.dll类型库。今天出现了一个很怪异的问题:我写的mapservice单独运行一切正常,静态测试完全通过,但将其拖入IMS Admin中却会失败,连启动时的静态测试代码都过不去,真是诡异至极。分析原因大概是从配置文件appconfig.ini中读取一些参数的时候出的问题,当程序中的GetPrivateProfileString(...)传入appconfig.ini的绝对完整路径时,就不会出现问题,而把路径改为".\\appconfig.ini"相对路径就会完蛋,又不能动态调试,所以十分郁闷,无奈之下考虑使用IMSUtil。过去一直以为vc6下面用不了这个东西,今天上ESRI论坛翻腾了一下,找到了上面那个链接,把问题解决了。不过这个例子是for ArcIMS的,使用MOIMS的时候要稍微改一下:
m_regparams.SetHostURL(
"
http://<your IP>/scripts/esrimap.dll
"
);

就可以了
参考:
Introduction
While ESRI provides excellent documentation and tutorials for MapObjects + IMS applications, I find that all of these documents are written with only Visual Basic in mind.
While the fundamental procedures are the same for Visual C++ , there are a number of small development environment-based differences which may be difficult for a C++ programmer to grasp.
Thus, I’ve taken the time to write my own tutorial for developing a MapObjects application for ArcIMS in Visual C++.
This tutorial assumes you are familiar with C++ and the Visual C++ environment.
This tutorial has been tested only with MapObjects 2.1 and ArcIMS 4.0.
Step 1: Create a new project with MapObjects and WebLink
1. Open Visual C++ and Select "New..." from the "File" menu
2. Click the "Projects" tab
3. Select "MFC AppWizard (exe)"
4. Give your project the name "IMSTutorial"
5. Click "OK"
6. Select "Dialog based" for your application type and click "Finish"
7. Click "OK" when the "New Project Information" window pops up
8. Click the "Project" menu, select "Add To Project", and click "Components and Controls"
9. Browse to the "Registered ActiveX Controls" directory
10. Select "MapObjects 2.1 Map Control" and click "Insert."
Click "OK" when it asks "Insert this component?"
11. Click "OK" in the "Confirm Classes" window – this adds all the MapObjects header and implementation files to your project.
12. Select "WebLink Control" and click "Insert."
Click "OK" when it asks "Insert this component?"
13.
Click "OK" in the "Confirm Classes" window – this adds the WebLink header and implementation files to your project.
14.
Click "Close" in the "Components and Controls Gallery" window
15.
The MapObjects and WebLink controls should now be on your Controls toolbar
16.
Click the "TODO: Place dialog controls here" label and delete it.
Add both a MapObjects and a WebLink control to the form by dragging each icon onto it.
Resize the MapObjects control to be a bit bigger.
17.
Next, we’re going to declare each of these components as member variables in the dialog class.
Click the "View" menu, and click "ClassWizard"
18.
Click the "Member Variables" tab.
This shows a list of all the controls on the dialog form.
19.
Double-click "IDC_MAP1"
For the variable name, type "m_map" (without quotes) and click "OK"
20.
Double-click "IDC_WEBLINKCTRL1"
For the variable name, type "m_weblink" (without quotes) and click "OK"
21.
Click "OK" in the ClassWizard window
22.
Test your project by pressing the F5 key.
The dialog window should pop up, and the weblink control should be invisible.
23.
Save your project
Step 2: Configuring MapObjects
- Add MapHelper.
In the MFC Common samples directory (default is C:\Program Files\ESRI\MapObjects2\Samples\MFC\Common) are three files that we need:
- MapObjects2.h
- MapHelper.h
- MapHelper.cpp
Using Windows Explorer, copy these files from this directory and paste them into your Visual C++ project’s directory.
- Add these three files to your project by clicking the "Project" menu, select "Add To Project", and click "Files…"
Select those three files listed above and click "OK"
- Open up your "stdafx.h" file from this project and add the following two lines after the existing #include directives:
#include "MapObjects2.h"
#include "MapHelper.h"
- Next, we’re going to add map data to the MapObjects Map Control.
Find the body to the
OnInitDialog() member function in the CIMSTutorialDlg class and find the following line:
// TODO: Add extra initialization here
Immediately below this line, add the following line of code:
AddLayer(m_map, "C:\\Program Files\\ESRI\\MapObjects2\\Samples\\Data\\World\\country.shp", moGreen);
The exact path to this data varies by installation.
(two backslashes are used because the backslash is an escape character)
- Test the application by pressing F5.
You should see the country boundaries in the MapObjects control
Step 3: Configuring WebLink
- Go back to the form editor (Click the ResourceView tab in the left pane, expand "IMS Tutorial Resources", expand "Dialog," double-click IDD_IMSTUTORIAL_DIALOG)
- Right-click the WebLink control and select "Properties."
Then click the "Control" tab.
- For LocalIP, enter the IP address of your computer.
Do not enter the localhost address (127.0.0.1) as it will not work correctly if you do so.
- For WebPort, enter 5062
- In the body to the OnInitDialog() member function in the CIMSTutorialDlg class, add the following line after the AddLayer() code that we added in the previous step:
if(!m_weblink.Start())
{
MessageBox("Could not start WebLink control");
}
This code opens the port you specified and begins listening for connections.
If an error occurs, a dialog box will pop up.
- Create a new virtual function OnFinalRelease() in the CIMSTutorialDlg class.
In the ClassView pane, right-click CIMSTutorialDlg and select "Add Virtual Function"
- Double-click "OnFinalRelease" and click "Edit Existing"
- In the OnFinalRelease() function, find the following line
// TODO: Add your specialized code here and/or call the base class
Immediately below it, add the following line of code:
m_weblink.Stop();
This code closes the port before the application quits.
9.
Finally, when the WebLink port is open and a request comes in, the application must handle it.
Open up the ClassWizard and select the "Message Maps" tab.
10.
Select the "CIMSTutorialDlg" class, the "IDC_WEBLINKCTRL1" object, and the "Request" message.
Then click "Add Function."
Accept the default function name by clicking "OK"
Then click "Edit Code"
11.
Find the following line in your new function:
// TODO: Add your control notification handler code here
Immediately below it, add the following code:
CMoStrings args(arguments);
CMoStrings vals(values);
args.m_bAutoRelease = false;
vals.m_bAutoRelease = false;