Onega

a lot of VC++ posts, a few C# posts, and some miscellaneous stuff

Wednesday, September 21, 2005

VBScript to install COM DLL as COM+ application

''' Create COM+ application via COMAdmin.COMAdminCatalog
''' Onega(www.fruitfruit.com)
''' SAMPLE usage BEGIN
test_prog_id = "scdebugutil.DebugStream"
start_time = Now()
register_result = register_com_plus_app(test_prog_id)
end_time = Now()

if register_result then
WScript.Echo "create COM+ application for " & test_prog_id & " successfully takes " _
& CStr(DateDiff("s",start_time,end_time)) & " seconds"
else
WScript.Echo "Failed to create COM+ application for " & test_prog_id & " takes " _
& CStr(DateDiff("s",start_time,end_time)) & " seconds"
end if
''' SAMPLE usage END


''' register COM+ application via its ProgID
''' return true if succeeded
function register_com_plus_app( ProgID)
com_application_name = ProgID
register_com_plus_app = false
On Error Resume Next
FPath = get_com_path_by_prog_id(ProgID)
if len(FPath) < 1 then
WScript.Echo ProgID & " can't be find in registry"
exit function
end if
Set objCat=CreateObject("COMAdmin.COMAdminCatalog")
Set objApps = objCat.GetCollection("Applications")
objApps.Populate
''' check if this application already exists
for each app in objapps
if app.Name = com_application_name then
WScript.Echo com_application_name & " already exists. Action aborted"
exit function
end if
next

''' Create a default application
objApps.Add
objApps.SaveChanges

Set objApp = objApps.Item(0)
Do While objApp.Name <> "New Application"
count = count + 1
Set objApp = objApps.Item(count)
Loop

if objApp.Name = "New Application" then

objApp.Value("Name") = com_application_name
objApps.SaveChanges
objCat.InstallComponent com_application_name, FPath, "", ""
objApps.SaveChanges
register_com_plus_app = true
end if
set objApps = nothing
set objCat = nothing
end function


''' get COM library path by its ProgID via looking registry
''' return empty string if the COM is not registered or invalid ProgID
function get_com_path_by_prog_id(com_prog_id)
Set WSHShell = WScript.CreateObject("WScript.Shell")
strRegKey = "HKCR\" & com_prog_id & "\CLSID\"
com_clsid = WSHShell.RegRead(strRegKey)
strRegKey = "HKCR\CLSID\" & com_clsid & "\InprocServer32\"
com_path = WSHShell.RegRead( strRegKey)
if len(com_path)<1 then
strRegKey = "HKCR\CLSID\" & com_clsid & "\LocalServer32\"
com_path = WSHShell.RegRead( strRegKey)
end if
get_com_path_by_prog_id = com_path
end function

Tuesday, September 20, 2005

blob in mssqlserver

''' large field shall use UPDATETEXT feature of MSSQLSERVER
''' AppendChunk does not work for fields large than 60MB
''' MSSQLSERVER blob processing: DATALENGTH UPDATETEXT ...

Set rs=CreateObject("ADOdb.recordset")
Set con = CreateObject("adodb.connection")
con.CommandTimeout = 1000000
con.open "Provider=SQLOLEDB;Data Source=;Initial Catalog=SC;User ID=sa;Password=kodak;"
adOpenStatic = 3
adLockOptimistic = 3
adCmdTable = 2
adCmdText = 1
adPersistXML = 1
adCmdUnknown = 8
adOpenKeyset = 1
adTypeBinary = 1
dim start_time
start_time = Now()
table_name = "blobtable"

rs.open table_name ,con,adOpenKeyset,adLockOptimistic,adCmdUnknown

for i = 1 to 10
set stream = createobject("ADODB.Stream")
stream.Type = adTypeBinary
stream.Open
stream.LoadFromFile "D:\Onega\020.pdf"
RS.Fields("blobfield").AppendChunk stream.Read
set stream = nothing
next
rs.update
rs.close
con.close
end_time = Now()

MsgBox "process blob field takes " & CStr(DateDiff("s",start_time,end_time)) & " seconds"

Monday, September 19, 2005

build libobjc via gnumake on windows

Modify the following line in makefile.dos in order to include gcc-4.0.1\libobjc\objc in header search path list
SUBDIR_INCLUDES = -I. -I.. -I../config -I./objc

I got the following error:
C:\>C:\Temp\make-3.80\WinRel\gnumake.exe -f makefile.dos
gcc -O2 -c -I. -I.. -I../config -I./objc hash.c
gcc -O2 -c -I. -I.. -I../config -I./objc sarray.c
gcc -O2 -c -I. -I.. -I../config -I./objc class.c
gcc -O2 -c -I. -I.. -I../config -I./objc sendmsg.c
sendmsg.c:32:21: tconfig.h: No such file or directory
sendmsg.c:33:23: coretypes.h: No such file or directory
sendmsg.c:34:16: tm.h: No such file or directory
sendmsg.c:38:26: runtime-info.h: No such file or directory
C:\Temp\make-3.80\WinRel\gnumake.exe: *** [sendmsg.o] Error 1

C:\>C:\Temp\make-3.80\WinRel\gnumake.exe -f makefile.in
process_begin: CreateProcess((null), LIBTOOL@ --mode=compile @CC@ -c -I. -I@glib
cpp_srcdir@ @CFLAGS@ -W -Wall -Wwrite-strings -Wstrict-prototypes @GTHREAD_FLAGS
@ -DIN_GCC -DIN_TARGET_LIBS -fno-strict-aliasing -I@glibcpp_srcdir@/objc -I@glib
cpp_srcdir@/../gcc -I@glibcpp_srcdir@/../gcc/config -I../../gcc -I@glibcpp_srcdi
r@/../include archive.c, ...) failed.
make (e=2): The system cannot find the file specified.
C:\Temp\make-3.80\WinRel\gnumake.exe: *** [archive.lo] Error 2

build cchess(http://sourceforge.net/projects/cchess) with Dev-CPP

I have downloaded SDL library and put SDL.lib,SDL_mixer.lib,
SDLmain.lib on the same directory as SDL_demo.dev
the absolute path of SDL_mixer.lib is also updated in
SDL_demo.dev
Now I have the following error:
Compiler: Default compiler
Building Makefile: "D:\Onega\test\cchess\Makefile.win"
Executing make...
make.exe -f "D:\Onega\test\cchess\Makefile.win" all
gcc.exe main.o token.o button.o chess.o combox.o edit.o
font.o game.o map.o obj_list.o pvsp.o rules.o selimg.o
block.o window.o trace.o audio.o -o "cchess.exe"
-L"d:/apps/Dev-Cpp/lib" -mwindows -lwsock32 -lmingw32
-lSDLmain -lSDL -mwindows
"D:/Onega/test/cchess/SDL_mixer.lib" -lobjc

d:\apps\Dev-Cpp\Bin\..\lib\gcc\mingw32\3.4.2\..\..\..\..\mingw32bin\ld.exe:
cannot find -lSDLmain
collect2: ld returned 1 exit status

make.exe: *** [cchess.exe] Error 1

steps to compile the source code with Dev-CPP
Download
http://www2.tw.freebsd.org/cygwin/release/gcc-mingw/gcc-mingw-obj
c/gcc-mingw-objc-20050522-1.tar.bz2
and unzip libobjc.a to D:\Apps\Dev-Cpp\lib\libobjc.a
Edit D:\Onega\test\cchess\SDL_demo.dev
remove "-lSDLmain -lSDL" from the following line
Linker=-lwsock32 -lmingw32 -lSDLmain -lSDL -mwindows
"D:\Onega\test\cchess\SDL_mixer.lib"_@@_
Build SDL library with VC++ 6.0, copy sdl.lib and
sdlmain.lib to
D:\Onega\test\cchess\SDL.a
D:\Onega\test\cchess\SDLmain.a
Add sdl.a and sdlmain.a to Dev-CPP project options
->parameters: linker
Modify D:\Onega\test\cchess\main.c
int APIENTRY WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
/*INT main(INT argc,CHAR * argv[])*/
{
GlobalInit();
Game_UIMain();
Game_Exec();
}

The build problem is fixed by phoenix96_2000(eXMe). He also
faced undefined references to '_alloca_probe' problem and
fixed it via adding winmm library -lwinmm

build gnumake on windows with VC++6.0

Open CMD window and run the following commands
C:\Temp\make-3.80>"C:\Program Files\Microsoft Visual Studio\VC98\Bin\VCVARS32.BAT"
C:\Temp\make-3.80>C:\Temp\make-3.80\build_w32.bat>build.log
I got the following error:
variable.obj : error LNK2001: unresolved external symbol _hash_init
...
There is a hint from JG that it is a bug of gnumake3.80
http://lists.gnu.org/archive/html/make-w32/2005-07/msg00082.html
So I modify build_w32.bat to add the following lines:

...
cl.exe /nologo /MT /W3 /GX /YX /O2 /I . /I glob /I w32/include /D NDEBUG /D WINDOWS32 /D WIN32 /D _CONSOLE /D HAVE_CONFIG_H /FR.\WinRel/ /Fp.\WinRel/%make%.pch /Fo.\WinRel/ /c hash.c
echo WinRel\hash.obj >>link.rel
...
.\WinRel/hash.obj

Now I am able to see the beautiful message: "WinRel build succeeded!"