-
question for penagate,moeur or codeblock pls regarding dll
this was codeblocks wrapper code to create a new link.exe regarding the win32dll. but im having problems with this
VB Code:
Option Explicit
Private Const LINK_FILE = "LINKER.EXE"
Dim FSO As FileSystemObject
Private Sub cmdCancel_Click()
Open App.Path & "\LinkerLog.txt" For Append As #1
Print #1, Now & ": ============================================"
Print #1, Now & ": Command Line Options: "; Command$
Print #1, Now & ": ============================================"
Print #1, vbCrLf & vbCrLf
Close #1
ShellWait App.Path & "\" & LINK_FILE & ".exe " & Command$
Unload Me
End Sub
Private Sub CmdOk_Click()
Dim CmdLine As String
CmdLine = Command$
CmdLine = Replace(CmdLine, "/ENTRY:__vbaS", "/ENTRY:DLLMain") ' BookMark #1
CmdLine = Replace(CmdLine, "/BASE:0x400000", "/BASE:0x10000000")
CmdLine = CmdLine & " /DLL /DEF:" & """" & txtCompiler.Text & """"
If Len(Dir(txtCompiler.Text, vbNormal)) <= 0 Then
MsgBox "No such DEF file.. please verify again!"
Exit Sub
End If
LINK CmdLine
End Sub
Private Sub Form_Load()
Dim intPos As Integer
Dim strPath As String
Dim fld As Folder
Dim fil As File
Set FSO = New FileSystemObject
' Determine if .DEF file exists
'
' Extract path from first .obj argument
intPos = InStr(1, Command$, ".OBJ", vbTextCompare)
strPath = Mid$(Command$, 2, intPos + 2)
intPos = InStrRev(strPath, "\")
strPath = Trim$(Left$(strPath, intPos - 1))
strPath = Replace$(strPath, """", "")
Debug.Print strPath
' MsgBox "Path=" & strPath
' Open folder
Set fld = FSO.GetFolder(strPath)
' MsgBox fld.Path
' Get files in folder
For Each fil In fld.Files
' MsgBox fil
If UCase$(FSO.GetExtensionName(fil)) = "DEF" Then
txtCompiler.Text = fil
Exit For
End If
Next
If txtCompiler.Text = vbNullString Then
LINK ' Default
Else
If MsgBox("Click Yes to apply DLL options over a Standard EXE Project," & vbCrLf & "otherwise click No to let VB handle the usual way.", vbYesNo) = vbNo Then
LINK ' Default
End If
End If
End Sub
Sub LINK(Optional CmdLine As String = vbNullString)
If CmdLine = vbNullString Then CmdLine = Command$
If CmdLine = vbNullString Then
Unload Me
Exit Sub
End If
Open App.Path & "\LinkerLog.txt" For Append As #1
Print #1, Now & ": ============================================"
Print #1, Now & ": Command Line Options: "; Command$
If CmdLine <> Command$ Then
Print #1, Now & ": Command Line Options: "; CmdLine ' Write only if there was a change
End If
Print #1, Now & ": ============================================"
Print #1, vbCrLf & vbCrLf
Close #1
ShellWait App.Path & "\" & LINK_FILE & " " & CmdLine ' i.e.: My SuperShell function
Unload Me
End Sub
Do i put this code in a *form* (i noticed CmdOK and CmdCancel functions in the code..) or a *module*?
Do i add any references to the project?
I keep getting an error with the 'shellwait' lines saing its not defined or something
Please may someone help me with this. It's just the linker part which im having problems with, awaiting your replies, many thanks in advance!!
-
Re: question for penagate,moeur or codeblock pls regarding dll
You need a reference to Microsoft Scripting Runtime to use the FileSystemObject and I'm guessing that ShellWait is a routine written by codeblock which shells to a process synchronously, ie waits for the process to finish before continuing. If I'm guessing correctly, this code should substitute for codeblock's ShellWait routine. Put this code in a module.
VB Code:
Option Explicit
'
' Windows API Declarations for executing (shell) a process synchronously
'
Private 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
Private Const STARTF_USESHOWWINDOW As Long = &H1
Private Const SW_HIDE As Long = &H0
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As Long, ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Sub ShellWait(ByVal cmd As String, Optional Parameters As String = "", Optional ByVal HideWindow As Boolean = False)
'
' Shell to a process and wait for it to finish executing
'
Dim ret As Long
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
'
' Initialize the STARTUPINFO structure
'
start.cb = Len(start)
'
' Hide the app's window if requested
'
If HideWindow Then
start.dwFlags = STARTF_USESHOWWINDOW
start.wShowWindow = SW_HIDE
End If
'
' Check for any passed parameters
'
If Trim(Parameters) <> "" Then
cmd = cmd & " """ & Parameters & """"
End If
'
' Start the shelled application
'
ret = CreateProcessA(0&, cmd, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
'
' Wait for the shelled application to finish
'
ret = WaitForSingleObject(proc.hProcess, INFINITE)
ret = CloseHandle(proc.hProcess)
End Sub
-
Re: question for penagate,moeur or codeblock pls regarding dll
ok thanks i done exactly what you said, plus i also put 2 buttons on the form (CmdOK and CmdCancel and a textbox - txtCompiler)..
I did 'Make Project1.exe' and it successfully made the exe, now do i simply use this exe as the new Link.exe?
(and change my original link.exe to LinkLnk.exe???)
thanks for all your help so far
-
Re: question for penagate,moeur or codeblock pls regarding dll
ok a bit of success.. however after tryig to build my dll source, it doesnt seem to make my dll file in the directory?
Quote:
10/1/2005 2:16:14 AM: ============================================
10/1/2005 2:16:14 AM: Command Line Options: "C:\Documents and Settings\Home\Desktop\MathLib_DLL\MathLib.OBJ" "C:\Documents and Settings\Home\Desktop\MathLib_DLL\MathLib1.OBJ" "C:\Program Files\Microsoft Visual Studio\VB98\VBAEXE6.LIB" /ENTRY:__vbaS /OUT:"C:\Documents and Settings\Home\Desktop\MathLib_DLL\MathLib.exe" /BASE:0x400000 /SUBSYSTEM:WINDOWS,4.0 /VERSION:1.0 /INCREMENTAL:NO /OPT:REF /MERGE:.rdata=.text /IGNORE:4078
10/1/2005 2:16:14 AM: Command Line Options: "C:\Documents and Settings\Home\Desktop\MathLib_DLL\MathLib.OBJ" "C:\Documents and Settings\Home\Desktop\MathLib_DLL\MathLib1.OBJ" "C:\Program Files\Microsoft Visual Studio\VB98\VBAEXE6.LIB" /ENTRY:DLLMain /OUT:"C:\Documents and Settings\Home\Desktop\MathLib_DLL\MathLib.exe" /BASE:0x10000000 /SUBSYSTEM:WINDOWS,4.0 /VERSION:1.0 /INCREMENTAL:NO /OPT:REF /MERGE:.rdata=.text /IGNORE:4078 /DLL /DEF:"C:\Documents and Settings\Home\Desktop\MathLib_DLL\MathLib.DEF"
10/1/2005 2:16:14 AM: ============================================
it should have made MathLib.dll in the directory where the project is?
when i was given this promp during the 'make MathLib.exe' -
"Click Yes to apply DLL options over a Standard EXE Project"
i clicked Yes, but the dll did not appear anywhere?? :confused: :confused: :confused:
-
Re: question for penagate,moeur or codeblock pls regarding dll
I'm not exactly sure what's happening... sorry :(
Maybe you could try sending codeblock a PM seeing as it's his code.
-
1 Attachment(s)
Re: question for penagate,moeur or codeblock pls regarding dll
ok it builds it into a .exe now, not a dll :(
i chose 'yes' from the linker option to create as a dll, but still it makes an exe in the directory :(
any ideas whats going wrong guys?
This is the linker im using:
-
Re: question for penagate,moeur or codeblock pls regarding dll
did you try renaming the exe to dll?
-
1 Attachment(s)
Re: question for penagate,moeur or codeblock pls regarding dll
ok i changed the exe to a dll, and then i made a brand new exe testing the dll, but it just keeps saying 'can't find the MathLib.dll'
Please can help me, i am desperate to get this working, thanks alot for all your help so far, this is the dll project and the dlltest project, please if you have time look at it, thanks
-
Re: question for penagate,moeur or codeblock pls regarding dll
If it can't find Mathlib.dll try moving it to your system32 directory
-
Re: question for penagate,moeur or codeblock pls regarding dll
i still getting:
run time error 48
file mathlib.dll not found
:( :( :confused:
-
Re: question for penagate,moeur or codeblock pls regarding dll
What did you move. Mathlib or your "dll" into system32? If it says its looking for Mathlib, then thats what you need to put in system32.
chem
-
Re: question for penagate,moeur or codeblock pls regarding dll
i pasted a copy of the MathLib.dll into the system32 folder, and it just keeps saying
run time error 48
file not found: MathLib.dll
-
Re: question for penagate,moeur or codeblock pls regarding dll
I can't help you with codeblock's wrapper, but if you want to try the one I poseted in that thread I can help.
-
Re: question for penagate,moeur or codeblock pls regarding dll
ok thanks, i used your wrapper code - i built it into link.exe and renamed the other original one to LinkLnk.exe. I put these in the vb directory..
i then do 'Make MathLib.exe", it asks me..
Make changes to link options, i click 'Yes' , and it creates MathLib.exe in the project directory.
i then change it to MathLib.dll
but im getting the same problem as before when i test the dll, i get a run time error saying the MathLib.dll was not found. :confused:
This is from lnklog.txt
Quote:
Beginning execution at 10/1/2005 9:12:38 PM
Command line arguments to LINK call:
"C:\Documents and Settings\Home\Desktop\MathLib[Test]\MathLib_DLL\MathLib.OBJ" "C:\Documents and Settings\Home\Desktop\MathLib[Test]\MathLib_DLL\MathLib1.OBJ" "C:\Program Files\Microsoft Visual Studio\VB98\VBAEXE6.LIB" /ENTRY:__vbaS /OUT:"C:\Documents and Settings\Home\Desktop\MathLib[Test]\MathLib_DLL\MathLib.exe" /BASE:0x400000 /SUBSYSTEM:WINDOWS,4.0 /VERSION:1.0 /INCREMENTAL:NO /OPT:REF /MERGE:.rdata=.text /IGNORE:4078
Command line arguments after modification:
"C:\Documents and Settings\Home\Desktop\MathLib[Test]\MathLib_DLL\MathLib.OBJ" "C:\Documents and Settings\Home\Desktop\MathLib[Test]\MathLib_DLL\MathLib1.OBJ" "C:\Program Files\Microsoft Visual Studio\VB98\VBAEXE6.LIB" /ENTRY:DLLMain /OUT:"C:\Documents and Settings\Home\Desktop\MathLib[Test]\MathLib_DLL\MathLib.exe" /BASE:0x10000000 /SUBSYSTEM:WINDOWS,4.0 /VERSION:1.0 /DEF:"C:\Documents and Settings\Home\Desktop\MathLib[Test]\MathLib_DLL\MathLib.def" /DLL /INCREMENTAL:NO /OPT:REF /MERGE:.rdata=.text /IGNORE:4078
Calling LINK.EXE linker
Returned from linker call
-
Re: question for penagate,moeur or codeblock pls regarding dll
Pouncer,
I am working on it
I have to get my brain back to where it was when I last worked on this problem.
One thing I remember is that if the VB linker runs into an error, it won't give you an error message, it simply does not produce the output file.
To get the error messages, I have to run the command through the VC++ linker in a CMD window. The command being the command line after modification from the log file.
You have to do this at the point that the link wrapper is asking you whether you want to proceed or not other wise the obj files will not exist.
Also, when you compile your exe, you can give it the dll name.
-
Re: question for penagate,moeur or codeblock pls regarding dll
moeur thanks you so much for all your time and effort for this, i really hope you can solve this problem!!
thanks alot, ill keep checking back on this thread
-
Re: question for penagate,moeur or codeblock pls regarding dll
OK, I got your code working with my wrapper.
If you are using my wrapper then decalre your dllmain function as so.
VB Code:
Public Function DllMain(ByVal hInst As Long, ByVal fdwReason As Long, lpvReserved As Long) As Long
Note case matters.
Now, I think your problem was that you have declared the path to your dll in the declaration of the functions.
VB Code:
Public Declare Function Increment Lib "C:\Documents and Settings\Home\Desktop\MathLib_DLL\MathLib.dll" (value As Integer) As Integer
Make sure that the dll resides in that directory and delete all other instances.
-
Re: question for penagate,moeur or codeblock pls regarding dll
wow moeur thats brilliantt!!!! you got it working on your side now i know there is 100% hope!!!!
but on my side, im using your wrapper code and done exactly as you wrote, i clicked on 'Make MathLib.dll' and i clicked yes on the prompt: 'Make changes to link options'
but it does not produce no MathLib.dll in the direcotry of the project :(
-
Re: question for penagate,moeur or codeblock pls regarding dll
Quote:
Originally Posted by Pouncer
i pasted a copy of the MathLib.dll into the system32 folder, and it just keeps saying
run time error 48
file not found: MathLib.dll
What OS are you using? You should only move it to System32 if it's XP, 2000, or NT. Otherwise it should be in your System folder.
-
Re: question for penagate,moeur or codeblock pls regarding dll
Quote:
but it does not produce no MathLib.dll in the direcotry of the project
Did you declare your DllMain exactly as I posted it? Cut and paste that declaration so that you don't make a type. The case of DllMain is important. My wrapper expects DllMain not DLLMain as codebank's wrapper expects.
-
1 Attachment(s)
Re: question for penagate,moeur or codeblock pls regarding dll
i check the code over and over and it is exactly how you wrote, i use DllMain in your linker and your exact dll declaration (which i pasted as you said), i cant seem to find the problem at all (im on win xp too, i looked in system32 and dll isnt there either)
here is everything, the dll, the project to test the dll, moeurs linker
but it just isnt producing the dll :(
-
Re: question for penagate,moeur or codeblock pls regarding dll
Oh,
I forgot :blush:
Remove the following line from your .def file
DLLMain @1
so the file should read
Code:
LIBRARY MathLib
EXPORTS
Increment @1
Decrement @2
Square @3
-
Re: question for penagate,moeur or codeblock pls regarding dll
moeur you are a absulute genius, i dnt know how much to thank you. and also the others too like penegate who kept replying back on the other thread.
ive made activex dlls before in vb, but never did i think it would be possible to create windows dll until penegate linked me to your hook thread
once again, thanks very much, im not gona test this windows dll from a different application, like an irc chat client - mIRC.
you help was much appreciated!!
-
Re: question for penagate,moeur or codeblock pls regarding dll
ok well, testing this dll in an irc chat client called mIRC, using something like
//echo -a $dll(MathLib.dll,Square,4)
(I put MathLib.dll in the directory to where the mIRC client is)
which should echo 16 in the client
but it crashes mIRC and this is the message i get, any ideas as to what is causing this
http://i4.photobucket.com/albums/y10...ness/error.png
This is the dll help guide from mircs documentation
Quote:
Technical notes
This section contains technical information for programmers who want to create DLLs for use with mIRC.
The routine in the DLL being called must be of the form:
int __stdcall procname(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause)
mWnd is the handle to the main mIRC window.
aWnd is the handle of the window in which the command is being issued, this might not be the currently active window if the command is being called by a remote script.
data is the information that you wish to send to the DLL. On return, the DLL can fill this variable with the command it wants mIRC to perform if any.
parms is filled by the DLL on return with parameters that it wants mIRC to use when performing the command that it returns in the data variable.
Note: The data and parms variables can each hold 900 chars maximum.
show is FALSE if the . prefix was specified to make the command quiet, or TRUE otherwise.
nopause is TRUE if mIRC is in a critical routine and the DLL must not do anything that pauses processing in mIRC, eg. the DLL should not pop up a dialog.
The DLL can return an integer to indicate what it wants mIRC to do:
0 means that mIRC should /halt processing
1 means that mIRC should continue processing
2 means that it has filled the data variable with a command which it wants mIRC to perform, and has filled parms with the parameters to use, if any, when performing the command.
3 means that the DLL has filled the data variable with the result that $dll() as an identifier should return.
Note: You may need to create a .def file with the procedure names exported when compiling your DLL
-
Re: question for penagate,moeur or codeblock pls regarding dll
The document says that your function should have the form
VB Code:
Public Function Square(ByVal mWnd as Long, ByVal aWnd as Long, ByVal strdata as String, _
ByVal parms As String, ByVal show as Long, ByVal nopause as Long) as Long
Is this what you have?
-
Re: question for penagate,moeur or codeblock pls regarding dll
Thanks for the reply, I just have
VB Code:
Public Function Square(var As Long) As Long
If Not IsNumeric(var) Then Err.Raise 5
Square = var ^ 2
End Function
Should I change that to add in the variables you just posted? I.e,
VB Code:
Public Function Square(ByVal mWnd As Long, ByVal aWnd As Long, ByVal strdata As String, _
ByVal parms As String, ByVal show As Long, ByVal nopause As Long, var As Long) As Long
If Not IsNumeric(var) Then Err.Raise 5
Square = var ^ 2
End Function
(I put the val variable at the end)
Edit* Just tried it, the square functions stop working in the dll, and still the same crash problem from mIRC
-
Re: question for penagate,moeur or codeblock pls regarding dll
Since I don't know anything about the $dll function I can't help.
One problem could be that you probably can't call your dll from non-VB programs.
-
Re: question for penagate,moeur or codeblock pls regarding dll
This was a small example mIRC dll (in c++ which i think you know fairly well)
http://www.team-clanx.org/articles/c...l%20tutor.html
I'm not sure but thats how the functions are in c++, but if this is a windows 32 dll, shouldnt it be accessible from any application? :(
-
Re: question for penagate,moeur or codeblock pls regarding dll
As mentioned in the thread about this topic, the dll is still not a true win32 dll. First of all, the dll doesn't initialize properly and second it needs to initialize all the VB runtime stuff. It won't do the later so it must be called from a VB app that has already initialized all the COM stuff.
-
Re: question for penagate,moeur or codeblock pls regarding dll
ok thanks alot for your help, i guess i need to move into the C++ area!