View previous topic :: View next topic |
Author |
Message |
Cyan Bloodbane
Joined: 25 Nov 2005 Posts: 23 Location: Somewhere in Italy
|
Posted: Fri Nov 25, 2005 14:58 Post subject: CreateProcess API |
|
|
Hi here.
I have a problem with the Kernel32 api CreateProcess.
The follow discussion has been copied from bioware's forums :
Quote: |
I have developed an application that allows to restart nwnx by remote.
But there is an error, when i call CreateProcess API To run nwnx (it seems the only api which starts nwnx correctly) nwserver gives error: "Could not estabilish network comunication, port may be in use".
But nwserver shows that error for everyport that i set in the ini file.I have also tried with command-line -port xxx.
Thanks in advance.
|
Does anyone knows where is the error? I used VB6.
Holavez |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Tue Nov 29, 2005 14:36 Post subject: |
|
|
Hard to tell.. does NWNX show the correct port and module name ? _________________ Papillon |
|
Back to top |
|
|
Cyan Bloodbane
Joined: 25 Nov 2005 Posts: 23 Location: Somewhere in Italy
|
Posted: Tue Nov 29, 2005 17:10 Post subject: |
|
|
Yes. it shows them correctly.
The server does not load the correct port from the ini file...it sets port "-1" and leave the ip-box empty.
It also does not load the module...
I tested with version 2.5.3.
Holavez |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Wed Nov 30, 2005 10:23 Post subject: |
|
|
Could be a path related problem... on the other hand, if nwnx is able to start nwserver, it should already be in the correct directory.
Did you try something simple like ShellExecute ? _________________ Papillon |
|
Back to top |
|
|
Cyan Bloodbane
Joined: 25 Nov 2005 Posts: 23 Location: Somewhere in Italy
|
Posted: Wed Nov 30, 2005 18:43 Post subject: |
|
|
Yes i did.Shell, ShellExecute, ShellExecuteEx, WinExec, don't start nwserver.
With those api it runs correctly, but nwnx does not start nwserver.
However i tried to execute a separate istance of nwserver with an other shell, and, when it goes down nwnx doesn't restart the server.
I don't be able to find the problem...Do you want to see the exec code?
Holavez |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Wed Nov 30, 2005 21:14 Post subject: |
|
|
Yes, please post it. I guess there is some problem with parameter passing. _________________ Papillon |
|
Back to top |
|
|
Cyan Bloodbane
Joined: 25 Nov 2005 Posts: 23 Location: Somewhere in Italy
|
Posted: Wed Nov 30, 2005 22:22 Post subject: |
|
|
Api Declaration code
Code: |
Public Const NORMAL_PRIORITY_CLASS = &H20
Public Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Public Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type
Public Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
|
Exec code
Code: |
Dim bProcess As Long
Dim sec As SECURITY_ATTRIBUTES
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
bProcess = CreateProcess(txNWNXPath.Text, " -module " & txModName.Text, sec, sec, 0, NORMAL_PRIORITY_CLASS, 0, Left(txNWNXPath.Text, Len(txNWNXPath.Text) - 9), start, proc)
|
This is the code.
Holavez |
|
Back to top |
|
|
dumbo
Joined: 21 Aug 2005 Posts: 21
|
Posted: Fri Dec 02, 2005 8:55 Post subject: |
|
|
i dont know vb
1. zero-fill STARTUPINFO struc (start)
2. start.cb = sizeof(STARTUPINFO)
3. bProcess = CreateProcess(txNWNXPath.Text, " -module " & txModName.Text, 0, 0, 0, NORMAL_PRIORITY_CLASS, 0, Left(txNWNXPath.Text, Len(txNWNXPath.Text) - 9), start, proc) |
|
Back to top |
|
|
Papillon x-man
Joined: 28 Dec 2004 Posts: 1060 Location: Germany
|
Posted: Fri Dec 02, 2005 12:19 Post subject: |
|
|
Hmm, what happens when you ommit the path parameter and run your .exe right in the NWN directory ? This is how nwnx does it. _________________ Papillon |
|
Back to top |
|
|
Cyan Bloodbane
Joined: 25 Nov 2005 Posts: 23 Location: Somewhere in Italy
|
Posted: Fri Dec 02, 2005 17:38 Post subject: |
|
|
@Papillon : Nothing...it gives the same error.
However i have also tried to run a .bat file with the nwnx path, and it doesn't start nwserver.
With 0 passed by paramter to the CreateProcess function, vb gives a compilation error...
I think the problem is vb .
Holavez |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Mon Dec 05, 2005 3:56 Post subject: |
|
|
dumbo wrote: | i dont know vb
1. zero-fill STARTUPINFO struc (start)
2. start.cb = sizeof(STARTUPINFO)
3. bProcess = CreateProcess(txNWNXPath.Text, " -module " & txModName.Text, 0, 0, 0, NORMAL_PRIORITY_CLASS, 0, Left(txNWNXPath.Text, Len(txNWNXPath.Text) - 9), start, proc) |
Does you ModName include a space?
Might be best to make the entire -module parameter into a string, and enquote the ModName
eg " -module "_"My Mod"_"_" _'s only for emphasis on the quoting (they are not included)
Gryphyn |
|
Back to top |
|
|
|