DllCall 32vs64 bit Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

DllCall 32vs64 bit

20 Feb 2018, 07:36

Hi Community :wave:

This dll helps convert doc and docx to plain text.

Recently 64bit version released, but it is not working the same way the 32 is working.

Please help me understand and use it.

Any help highly appreciated, thanks in advance :clap:

xd2tx2161_x64.zip = https://drive.google.com/open?id=1BkioN ... 978U2nIbMb

32bit Version PERFECT

Code: Select all

MsgBox, 262144,%AppName% %A_LineNumber%, % ExtractText(Content, FilePath)

ExtractText(ByRef OutputVar, Search)
{
	static hModule := DllCall("LoadLibrary", "Str", "xd2txlib.dll", "Ptr")
	fileLength := DllCall("xd2txlib\ExtractText", "Str", Search, "Int", False, "Int*", fileText)
	OutputVar := StrGet( fileText, fileLength / 2 )
}
Return
Something I think might benefit in understand

Code: Select all

          ExtractText( fileName, False, fileText)
          
--------------------------------------------- 
                    
        public delegate int ExtractText(
          [MarshalAs(UnmanagedType.BStr)] String lpFileName,
          bool bProp,
          [MarshalAs(UnmanagedType.BStr)] ref String lpFileText);


	string fileName = "sample.doc";
        string fileText = "";
        // "®"I‚Édll‚ðƒ[ƒh‚µAŽg—pŒã‚ɉð•ú
        IntPtr handle = LoadLibrary("xd2txlib.dll");
        IntPtr funcPtr = GetProcAddress(handle, "ExtractText");

        ExtractText extractText = (ExtractText)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(ExtractText));
        int fileLength = extractText(fileName, false, ref fileText);
        FreeLibrary(handle);



64bit Version Help File

Code: Select all

 xd2txlib.dll‚ɂ‚¢‚Ä

xdoc2txt‚ÌDLL"Å‚Å‚·B
'˜ìŒ E—˜—pðŒ‚́Axdoc2txt‚ɏ€‚¶‚Ü‚·B


 "z•zƒtƒ@ƒCƒ‹

xd2txlib.dll	xdoc2txt DLL"Å
Sample1/*	C# ƒTƒ"ƒvƒ‹ƒvƒƒOƒ‰ƒ€(DllImport"ŁF"ñ„§)
Sample2/*	VB.Net ƒTƒ"ƒvƒ‹ƒvƒƒOƒ‰ƒ€(DllImport"ŁF"ñ„§)
Sample3/*	C++ ƒTƒ"ƒvƒ‹ƒvƒƒOƒ‰ƒ€
Sample4/*	C# ƒTƒ"ƒvƒ‹ƒvƒƒOƒ‰ƒ€(LoadLibrary"ŁF„§)
Sample5/*	VB.Net ƒTƒ"ƒvƒ‹ƒvƒƒOƒ‰ƒ€(LoadLibrary"ŁF„§FVisual Studio2010—p)
FileFind/*	C# ƒTƒ"ƒvƒ‹ƒvƒƒOƒ‰ƒ€iƒtƒ@ƒCƒ‹ŒŸõƒNƒ‰ƒCƒAƒ"ƒg‚Ì—áj

 'ˆÓŽ–€

Exd2txlib.dll(64bit"Å)‚ðŒÄ‚яo‚·ƒAƒvƒŠƒP[ƒVƒ‡ƒ"‚ðŠJ"­‚·‚é‚Æ‚«‚́Aƒ^[ƒQƒbƒgCPU‚ðAnyCPU‚É‚·‚é•K—v‚ª‚ ‚è‚Ü‚·B
	C#	ƒvƒƒpƒeƒB¨ƒrƒ‹ƒh¨ƒvƒ‰ƒbƒgƒtƒH[ƒ€ƒ^[ƒQƒbƒg(G): AnyCPU
	VB.Net	ƒvƒƒpƒeƒB¨ƒRƒ"ƒpƒCƒ‹¨Ú×ƒRƒ"ƒpƒCƒ‹ƒIƒvƒVƒ‡ƒ"(A)¨ƒ^[ƒQƒbƒgCPU(U):AnyCPU

Exd2txlib.dll‚ÍCOMƒIƒuƒWƒFƒNƒg‚Å‚Í‚ ‚è‚Ü‚¹‚ñ‚̂ŁADllImport‚Ü‚½‚ÍLoadLibrary‚ŌĂяo‚·•K—v‚ª‚ ‚è‚Ü‚·B
@‹ï'Ì"I‚ÈŽg—p•û–@‚̓Tƒ"ƒvƒ‹ƒvƒƒOƒ‰ƒ€‚ðŽQÆ‚µ‚Ä‚­‚¾‚³‚¢B

Eyd—vzxd2txlib.dll‚̃[ƒh•û–@‚́ADllImport‚Ü‚½‚ÍLoadLibrary‚Ì•û–@‚ª‚ ‚è‚Ü‚·‚ªA
@DllImport"ł̓AƒvƒŠƒP[ƒVƒ‡ƒ"‚ªI—¹‚·‚é‚܂сƒ‚ƒŠ‚ª‰ð•ú‚³‚ê‚È‚¢‚½‚߁A
@—\Šú‚µ‚È‚¢"ü—̓tƒ@ƒCƒ‹‚É‚æ‚éƒNƒ‰ƒbƒVƒ…‚ª‹N‚«‚½ê‡‚ɃAƒvƒŠƒP[ƒVƒ‡ƒ"Ž©'Ì‚ªˆÙíI—¹‚·‚é‰Â"\«‚ª‚ ‚è‚Ü‚·B
  ˜A'±‚µ‚ăeƒLƒXƒg'Šo‚ðs‚¤ê‡‚́A1ƒtƒ@ƒCƒ‹‚Ì'Šo–ˆ‚ÉLoadLibrary & FreeLibrary‚Å
@–ˆ‰ñxd2txlib.dll‚ðƒ[ƒhE‰ð•ú‚·‚邱‚Æ‚ð‚¨Š©‚ß‚µ‚Ü‚·BSample4,Sample5‚ðŽQÆ‚µ‚Ä‚­‚¾‚³‚¢B

Exd2txlib.dll(xdoc2txt)‚̓ƒ‚ƒŠã‚Ńtƒ@ƒCƒ‹‚Ì"WŠJ‚¨‚æ‚уGƒ"ƒR[ƒh‚ðs‚¤‚½‚߁AŽÀƒƒ‚ƒŠ‚ð'´‚¦‚鋐'å‚ȃtƒ@ƒCƒ‹‚͈µ‚¦‚Ü‚¹‚ñB
Exd2txlib.dll‚̓Tƒ|[ƒg‚µ‚Ä‚¢‚éŠg'£ŽqˆÈŠO‚̓eƒLƒXƒgƒtƒ@ƒCƒ‹‚ÆŒ©‚È‚µ‚ăGƒ"ƒR[ƒh‚ðŽŽ‚Ý‚Ü‚·BƒoƒCƒiƒŠƒtƒ@ƒCƒ‹‚Å‚ÍŽg—p‚µ‚È‚¢‚Å‚­‚¾‚³‚¢B


'è‹`F
int ExtractText(BSTR lpFileName,	// "ü—̓tƒ@ƒCƒ‹–¼
		bool bProp,		// T:ƒvƒƒpƒeƒB‚Ì'Šo F:–{•¶ƒeƒLƒXƒg‚Ì'Šo
		BSTR *lpFileText)	// 'Šo‚µ‚½ƒeƒLƒXƒg

int ExtractTextEx(BSTR lpFileName,	// "ü—̓tƒ@ƒCƒ‹–¼
		bool bProp,		// T:ƒvƒƒpƒeƒB‚Ì'Šo F:–{•¶ƒeƒLƒXƒg‚Ì'Šo
		BSTR lpOptions,		// ƒRƒ}ƒ"ƒhƒ‰ƒCƒ"ƒIƒvƒVƒ‡ƒ"(-r -o -g -x ‚Ì‚Ý—LŒø)
		BSTR *lpFileText)	// 'Šo‚µ‚½ƒeƒLƒXƒg


	ƒeƒLƒXƒg‚Ì'ŠoŒ‹‰Ê‚ÍUTF16‚Å‚·B


C#‚Ì—á(1)FDllImport"Å

       [DllImport("xd2txlib.dll", CharSet = CharSet.Unicode,
            CallingConvention = CallingConvention.Cdecl)]
       public static extern int ExtractText(
       [MarshalAs(UnmanagedType.BStr)] String lpFileName,
       bool bProp,
       [MarshalAs(UnmanagedType.BStr)] ref String lpFileText);

	string fileName = "sample.doc";
	string fileText = "";
	int fileLength = ExtractText( fileName, false, ref fileText );

C#‚Ì—á(2)F"®"Iƒ[ƒh"Łi„§j

        // LoadLibraryAFreeLibraryAGetProcAddress‚ðƒCƒ"ƒ|[ƒg
        [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
        internal static extern IntPtr LoadLibrary(string lpFileName);
        [DllImport("kernel32", SetLastError = true)]
        internal static extern bool FreeLibrary(IntPtr hModule);
        [DllImport("kernel32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = false)]
        internal static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);

        // ŠÖ"‚ðdelegate‚Ő錾‚·‚é
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        public delegate int ExtractText(
          [MarshalAs(UnmanagedType.BStr)] String lpFileName,
          bool bProp,
          [MarshalAs(UnmanagedType.BStr)] ref String lpFileText);


	string fileName = "sample.doc";
        string fileText = "";
        // "®"I‚Édll‚ðƒ[ƒh‚µAŽg—pŒã‚ɉð•ú
        IntPtr handle = LoadLibrary("xd2txlib.dll");
        IntPtr funcPtr = GetProcAddress(handle, "ExtractText");

        ExtractText extractText = (ExtractText)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(ExtractText));
        int fileLength = extractText(fileName, false, ref fileText);
        FreeLibrary(handle);


VB.Net‚Ì—á(1)FDllImport"Å

    <DllImport("xd2txlib.dll", SetLastError:=True, CharSet:=CharSet.Unicode, CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function _
        ExtractText( _
        <MarshalAs(UnmanagedType.BStr)> ByVal lpFileName As String, _
         ByVal bProp As Boolean, _
         <MarshalAs(UnmanagedType.BStr)> ByRef lpFileText As String _
        ) As Integer
    End Function


    Dim fileName As String
    Dim fileText As String

    fileName = "sample.doc"
    fileText = ""

    ExtractText( fileName, False, fileText)

VB.Net‚Ì—á(2)F"®"Iƒ[ƒh"Łi„§j

    '********************************************************
    '*  LoadLibrary,FreeLibrary,GetProcAddress ‚̐錾
    '********************************************************
    <DllImport("kernel32", CharSet:=CharSet.Auto, SetLastError:=True)> _
    Private Shared Function LoadLibrary(ByVal lpFileName As String) As IntPtr
    End Function

    <DllImport("kernel32", CharSet:=CharSet.Auto, SetLastError:=True)> _
    Private Shared Function FreeLibrary(ByVal hModule As IntPtr) As Boolean
    End Function

    <DllImport("kernel32", CharSet:=CharSet.Ansi, SetLastError:=True)> _
    Private Shared Function GetProcAddress(ByVal hModule As IntPtr, ByVal lpProcName As String) As IntPtr
    End Function

    '********************************************************
    '* ExtractText‚̐錾
    '********************************************************
    <UnmanagedFunctionPointer(CallingConvention.Cdecl)> _
    Delegate Sub ExtractText( _
        <MarshalAs(UnmanagedType.BStr)> ByVal lpFileName As String, _
        ByVal bProp As Boolean, _
        <MarshalAs(UnmanagedType.BStr)> ByRef lpFileText As String _
        )

	Dim fileText As String
	Dim fileName As String
	fileText = ""
	fileName = "sample.doc"

	' xd2txlib.dll ‚ðLoadLibraryŒo—R‚э[ƒh
	Dim TaragetDll As String = "xd2txlib.dll"
	Dim TaragetFunc As String = "ExtractText"
	Dim hModule As UInt32 = LoadLibrary(TaragetDll)
	If hModule = 0 Then
	TextBox1.Text = "xd2txlib.dll not found"
	Exit Sub
	End If

	' •ÏŠ·‚ÌŽÀs
	Dim ptr As IntPtr
	ptr = GetProcAddress(hModule, "ExtractText")

	If ptr <> IntPtr.Zero Then
		Dim dllFunc As ExtractText = _
		Marshal.GetDelegateForFunctionPointer( _
		ptr, _
		GetType(ExtractText) _
		)

		Call dllFunc(fileName, False, fileText)

	End If


	' DLL‚̉ð•ú
	Call FreeLibrary(hModule)


 ŒÄ‚яo‚µ•ûŽ®

ExtractText  ‚̌Ăяo‚µ•ûŽ®‚Ístdcall‚Å‚Í‚È‚­cdecl‚Å‚·‚̂ŁAŒÄ‚яo‚µŽž‚É–¾Ž¦‚µ‚Ä‚­‚¾‚³‚¢B
iƒTƒ"ƒvƒ‹ƒvƒƒOƒ‰ƒ€ŽQÆj
srdcall‚ŌĂяo‚·‚ƁAƒXƒ^ƒbƒN‚ª•sˆÀ'è‚É‚È‚é‰Â"\«‚ª‚ ‚è‚Ü‚·B


  —š—ð
2017/07/05	64bit"Å'ljÁ
2012/11/15	ˆø"‚Ì•À‚Ñ‚ðCOMƒRƒ"ƒ|[ƒlƒ"ƒg"Å‚Æ"¯‚¶‚É‚µ‚½
2012/11/13	xdoc2txt 2.0‚ÌDLL"Å‚Æ‚µ‚Ä"z•z
2014/06/14	"®"Iƒ[ƒh‚̃Tƒ"ƒvƒ‹(Sample4,Sample5)‚ð'ljÁ
2015/03/11	ŒÄ‚яo‚µ‹K–ñcdecl‚𖾎¦

just me
Posts: 9450
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: DllCall 32vs64 bit

20 Feb 2018, 09:59

If this is 'working perfectly' on 32-bit

Code: Select all

ExtractText(ByRef OutputVar, Search)
{
	static hModule := DllCall("LoadLibrary", "Str", "xd2txlib.dll", "Ptr")
	fileLength := DllCall("xd2txlib\ExtractText", "Str", Search, "Int", False, "Int*", fileText)
	OutputVar := StrGet( fileText, fileLength / 2 )
}
this might work on 32-bit and 64-bit

Code: Select all

ExtractText(ByRef OutputVar, Search)
{
	static hModule := DllCall("LoadLibrary", "Str", "xd2txlib.dll", "Ptr")
	fileLength := DllCall("xd2txlib\ExtractText", "Str", Search, "Int", False, "Ptr*", fileText)
	OutputVar := StrGet( fileText, fileLength / 2 )
}
The last parameter of ExtractText() is a pointer (Ptr). The size of a pointer is 4 bytes on 32-bit (which is equal to the size of an Integer) but 8 bytes on 64-bit.
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: DllCall 32vs64 bit

21 Feb 2018, 02:27

sorry its not
just me wrote:If this is 'working perfectly' on 32-bit

Code: Select all

ExtractText(ByRef OutputVar, Search)
{
	static hModule := DllCall("LoadLibrary", "Str", "xd2txlib.dll", "Ptr")
	fileLength := DllCall("xd2txlib\ExtractText", "Str", Search, "Int", False, "Int*", fileText)
	OutputVar := StrGet( fileText, fileLength / 2 )
}
this might work on 32-bit and 64-bit

Code: Select all

ExtractText(ByRef OutputVar, Search)
{
	static hModule := DllCall("LoadLibrary", "Str", "xd2txlib.dll", "Ptr")
	fileLength := DllCall("xd2txlib\ExtractText", "Str", Search, "Int", False, "Ptr*", fileText)
	OutputVar := StrGet( fileText, fileLength / 2 )
}
The last parameter of ExtractText() is a pointer (Ptr). The size of a pointer is 4 bytes on 32-bit (which is equal to the size of an Integer) but 8 bytes on 64-bit.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: DllCall 32vs64 bit

21 Feb 2018, 03:09

- Perhaps try adding Ptr at the end:
fileLength := DllCall("xd2txlib\ExtractText", "Str", Search, "Int", False, "Ptr*", fileText, "Ptr")
- Perhaps try specifying fileLength as an arbitrary number like 10, to see if fileText is valid.
- What does fileLength return? What about A_LastError?
- Is the 32-bit dll being called both times?
- (I noticed that Cdecl was mentioned, although that would only be a problem for the 32-bit dll, and not the 64-bit dll AFAIK.)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: DllCall 32vs64 bit

21 Feb 2018, 03:39

Nah the return type is an integer.
But this is using the CDECL calling convention:
Though as you mentioned it's only going to cause issues for the 32 bit version.

Code: Select all

DllCall("xd2txlib\ExtractText", "WStr", Search, "Int", False, "Ptr*", fileText, "Cdecl int") ;this is the most i could extract from that gibberish that you call help file ( honestly most of the text can't be read on my PC )
;It looks like: Š Ö " ‚ ð d e l e g a t e ‚ Å é Œ ¾ ‚ · ‚ é 
OK seems I was incorrect. It's not expecting a AutoHotkey Str type but rather something else.
https://docs.microsoft.com/en-us/dotnet ... or-strings
Recommends AHK Studio
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: DllCall 32vs64 bit

21 Feb 2018, 03:50

@nnnik: Ah yes thanks, it says 'int ExtractText', so Int, I'd read some other part that made me think it might be a Ptr.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: DllCall 32vs64 bit

21 Feb 2018, 06:13

The code works fine here without modification. So I guess you are using 32-bit AHK to call 64-bit dll?
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: DllCall 32vs64 bit

21 Feb 2018, 07:15

Hi,

Code: Select all

#persistent
#SingleInstance Force

MsgBox, 262144,%AppName% %A_LineNumber%, % ExtractText(Content, "Document.doc")

ExtractText(ByRef OutputVar, Search)
{
	static hModule := DllCall("LoadLibrary", "Str", "xd2txlib.dll", "Ptr")
	fileLength := DllCall("xd2txlib\ExtractText", "Str", Search, "Int", False, "Ptr*", fileText)
	OutputVar := StrGet( fileText, fileLength / 2 )
}
I am testing with
64bit Win10
AutoHotkeyU64.exe
xd2txlib.dll (64 bit)

I have attached zip containing word doc, script, dll, and AutoHotkeyU64.exe
https://drive.google.com/open?id=1Euewl ... uMzFTVB30a

I checked twice the OS, Ahk Version, and Dll but in vain

Please guide me :headwall:
Guest

Re: DllCall 32vs64 bit

21 Feb 2018, 07:24

Code: Select all

ExtractText(Content, "Document.doc")
MsgBox, 262144,%AppName% %A_LineNumber%, % Content
:roll:
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: DllCall 32vs64 bit

21 Feb 2018, 09:42

As Guest wrote, the result is stored in the first parameter.
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: DllCall 32vs64 bit

21 Feb 2018, 13:05

Tried the same from the guest, but again blank :roll:
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: DllCall 32vs64 bit

22 Feb 2018, 07:49

Thanks a lot everyone :dance: , especially "tmplinshi & Guest". :bravo:

I can't express my happiness, may our creator bless you guys with best of both worlds :salute:
Guest wrote:Then install https://www.microsoft.com/en-us/downloa ... x?id=13523 ... and make the changes I posted previously.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: RickC and 142 guests