regsvr32 fails for simple freepascal COM dll - dll

I'm completely new to free-pascal and I try to implement a simple dll that should register a COM class.
Unfortunately I could only find little information about COM Programming for freepascal. Thus I hope that someone here can give me some hints or even a link to some examples.
So here is what I did:
my operating system is Windows 7 64 bit
downloaded and installed Lazarus 32bit version
Version #: 1.2.6
Date: 2014-10-11
FPC: Version 2.6.4
SVN Revision: 46529
i386-win32-win32/win64
installed the ActiveX package in Lazarus
made a new project - type Library with a simple TAutoObject and a default TAutoObjectFactory for the COM registration: source code included after this description
build the dll
use regsvr32.exe to register my dll --> this fails with
"make sure the binary is stored at the specified path ..."
Invalid access to memory location.
then I tried to change the default project options:
under Compiler Options - Config and Target, I set
Target OS: Win32
Target CPU family: i386
still the same error occurs
Project source
library LazarusSimpleComRegTest;
{$mode objfpc}{$H+}
uses
Classes,
{ you can add units after this }
ComServ, MyComObj;
exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;
end.
MyComObj Unit:
unit MyComObj;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, ComObj;
const
CLASS_Plugin: TGUID = '{5E020FB0-B593-4ADF-9288-801C2FD432CF}';
type
TPlugin = class(TAutoObject)
end;
implementation
uses ComServ;
initialization
TAutoObjectFactory.Create(ComServer, TPlugin, CLASS_Plugin,
ciMultiInstance, tmApartment);
end.

I think the main problem was, that I did not include the type library as a resource in my dll file: Now it works fine.
I've made a very basic and simple working example on git-hub with some basic documentation:
lazarus-com-example

Related

Compile a 16-bit Windows DLL with Open Watcom

I'm trying to compile a 16-bit Windows DLL for this for this question on the reverseengineering stackexchange.
Below is my absolute minimum source files:
mydll.c
int main (int reason) {
return 0;
}
mydll.lnk
FORMAT WINDOWS DLL
LIBPATH .\openwatcom\lib286
LIBPATH .\openwatcom\lib286\win
LIBRARY windows
FILE mydll.obj
NAME mydll
I'm them using the following two commands to compile and link the DLL.
# Build
openwatcom\binnt\wcc.exe -i='openwatcom\h;openwatcom\h\win' -bd -w4 -d2 -zu -bt=windows -fo=.obj -ml mydll.c
# Link
openwatcom\binnt\wlink.exe #mydll.lnk
But for some reason the linking steps fails with the following messages:
Error! E2028: __DLLstart_ is an undefined reference
Error! E2028: __fpmath is an undefined reference
creating a Windows dynamic link library
file clibl.lib(sigfpe.c): undefined symbol __fpmath
My goal is just to be able to build a 16 bit DLL file, preferably from wine on my Mac, but I also have a Windows XP virtual machine so that's acceptable as well.

Unable to load dynamic library php_sqlsrv_7_nts.dll is not a valid Win32 application

Thought I'd see if there were any sql server drivers for php 7. Another question on Stack Overflow pointed me to these drivers here
So I install php_sqlsrv_7_nts.dll into my ext folder and add the following line to my php.ini:
extension=php_sqlsrv_7_nts.dll
I get this warning on every php script I run:
Warning: PHP Startup: Unable to load dynamic library 'C:\php7\ext\php_sqlsrv_7_nts.dll' - %1 is not a valid Win32 application
I realise this is just a pre-release version and there are many things to iron out still, but I was hoping to at least do some basic things.
What am I doing wrong, or do I need to wait a bit more for a better release.
Some info that might be useful:
PHP Version => 7.0.5
System => Windows NT GB275L-I-T-5654 6.3 build 9600 (Windows 8.1 Professional Edition) i586
Build Date => Mar 30 2016 09:57:56
Compiler => MSVC14 (Visual C++ 2015)
Architecture => x86
Configure Command => cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--disable-zts" "--with-pdo-oci=c:\php-sdk\oracle\x86\instantclient_12_1\sdk,shared" "--with-oci8-12c=c:\php-sdk\oracle\x86\instantclient_12_1\sdk,shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--without-analyzer" "--with-pgo"
Finally got this solved. Needed to install some more things before it would work, namely:
Microsoft Visual C++ 2015 Redistributable (x86) which you can get from here
The ODBC drivers which you can get from here
It works for me.
1.Download the extension windows 7.0
https://github.com/Microsoft/msphpsql/releases
2.And then according to the system requirement paste it in ext folder.
Note: Paste only the thread safe version (php_pdo_sqlsrv_7_ts.dll , php_sqlsrv_7_ts.dll)
3.And edit the php.ini file add this extension to your php.ini file and restart and check
The extension file from Github MSPHPSQL releases did not work for me and gave me the same predicament with the OP. I went to this Microsoft article which gave me the driver (extension) for MSSQL Server, go ahead and install it on a directory you can easily find, in my case I saved it in my c:\mssql-driver then inside get the extension (DLL) file that fits your OS and PHP version, in my case since I am using PHP 7.2.x and x64 Windows I picked the following file and put it in my PHP extension directory c:\xampp\php\ext:
php_pdo_sqlsrv_72_ts_x64.dll
php_sqlsrv_72_ts_x64.dll
and in my php.ini located in c:\xampp\php\php.ini defined it under the Dynamic Extensions section:
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
...
extension=curl
extension=php_pdo_sqlsrv_72_ts_x64.dll
extension=php_sqlsrv_72_ts_x64.dll
...
delete the "php_" on "php_sqlsrv_7_nts". just write "sqlsrv_7_nts"

When importing Nim module for Lua bindings, error shows: "could not load: lua(|5.1|5.0).dll"

I'm new to the Nim programming language, and coming from a Lua background, it excited me to find out that there is a module for adding Lua bindings to Nim.
I installed Nimble (Nim's package manager) for Windows and executed "nimble install lua" to download and install the correct module. Upon trying to import it and compile the source, this happened:
C:\Users\Ashley\Desktop\Stuff\Coding\Nim\Projects\LuaTest>nim c -r "C:\Users\Ashley\Desktop\Stuff\Coding\Nim\Projects\LuaTest\main.nim"
Hint: system [Processing]
Hint: main [Processing]
Hint: lua [Processing]
CC: main
CC: lua_lua
Hint: [Link]
Hint: operation successful (10698 lines compiled; 1.262 sec total; 16.163MB; Debug Build) [SuccessX]
could not load: lua(|5.1|5.0).dll
Error: execution of an external program failed: 'c:\users\ashley\desktop\stuff\coding\nim\projects\luatest\main.exe '
I have Lua 5.1 already installed with the proper entries in PATH. It's located in Program Files (x86). The directory contains a dll called lua5.1.dll. I tried looking up the error on Google, but there were no results that helped. What could be the problem?
On Windows you can put the library at the same place as the generated binary. In this case the file should be called lua.dll, lua5.1.dll or lua5.0.dll. Also make sure that the library and binary are both for the same system architecture, either x86 (32bit) or x86-64 (64bit).

JNI UnsatisfiedLinkError- how do I load libraries correctly?

I'm trying to work with the Java sample Database program from the CardScan SDK.
I am working with files located in Java/JNI and Java/Database. The program must be run with a 32 bit JRE. I was able to do so on a 64 bit machine by uninstalling Java and installing the 32 bit version, then re-adding the system path for Java. I can run the program and interface with a CardScan database file (.cdb) successfully by double clicking the SDKData.bat file, but when I open the source files for editing and edit the Java.library.path to include the required library (CRTK_JNI.dll), I get UnsatisfiedLinkErrors everywhere:
Exception in thread "main" java.lang.UnsatisfiedLinkError: sdkdata.CRTK.CRTK_Init([I)I
at sdkdata.CRTK.CRTK_Init(Native Method)
at sdkdata.CRTK.(CRTK.java:239)
at sdkdata.SDKData.(SDKData.java:97)
at sdkdata.SDKData.main(SDKData.java:643)
Java Result: 1
Presumably this is happening because the library is not loading properly.
What do I need to do to run and edit the program at full capacity (with all the native functions from CRTK_JNI in working order)?
Presumably this is happening because the library is not loading properly.
On the contrary. The library load is complete. You aren't getting that from a System.load()/loadLibrary() call, you are getting the error when calling your native method, the one that should have the signature:
package sdkdata;
public class CRTK
{
public native int CRTK_Init(int[]);
}
So it isn't there, or you have changed the signature without regenerating the .h and .c files, or you have manually mangled the declaration some other way.
Post your code.
To clarify, this Java sample program is officially unsupported by the CardScan API - it was a bad idea to try to use the API with an unsupported language relying solely on an experimental implementation. I ended up using one of the supported languages (Visual Basic) to work with the SDK; if anyone looking at this question happens to be struggling with using the CardScan API, here is my VB implementation on Github.

Another JNI UnsatisfiedLinkError DLL problem

I've read lots of posts about this, but none address my problem.
I have a very small DLL that allows a Java process to send windows messages. It simply calls
FindWindowEx(...)
SendMessage(...)
I have compiled that with VS2005 and linked with /MT and all's fine, but if I try to make my DLL depend on MSVCRT and link with /MD then I get the unsatisfied link error.
java.lang.UnsatisfiedLinkError: MyDll.dll: Can't find dependent libraries
According to depends.exe it has two missing DLLs, GPSVC.DLL and IESHIMS.DLL. The first exists in c:\windows\system32 and the second is in a winsxs path. There are LOADS of other DLLs loaded from c:\windows\system32 and GPSVC.DLL is an odd one in that even as admin on my win7x64 machine, I cannot run depends on that - it says it's not found...
Anyway, I tried forcing a load of both of those DLLs in my Java by (simplified - I'm not in control of java.library.path)
Field field = ClassLoader.class.getDeclaredField("usr_paths");
field.setAccessible(true);
String[] paths = (String[]) field.get(null);
String[] tmp = new String[paths.length + 2];
System.arraycopy(paths, 0, tmp, 0, paths.length);
tmp[paths.length] = "c:/windows/system32";
tmp[paths.length + 1] = "c:/Windows/winsxs/amd64_microsoft-windows-ie-ieshims_31bf3856ad364e35_8.0.7601.17514_none_c06d7c9c27da8591";
field.set(null, tmp);
but that made no difference. I can fallback to make it statically linked, but I'd rather not.
Any ideas on what I can try next?
Antony
Well, I´m using Visual Studio 2010 but it could work on 2005 too.
You could try configuring the VC compiler using vcvarsall.bat that you can find in ProgramFiles in /MicrosoftVisualStudio20xx/VC .
You have only to launch vsvarsall.bat in Command Line with one of these options: x86 or ia64 or x86_amd64 or x86_ia64. I don´t know if it will help but it could be one of the problems that VC compiler is not configured to work with 64 bit machine.
When I´m working with JNI I use command line to compile the code and I had to configure the compiler on 64 bit machine.
Or you could pobably try to compile it via Command Line. Here is my favourite tutorial http://www.ibm.com/developerworks/java/tutorials/j-jni/index.html