CodeBase-for-DBF icon indicating copy to clipboard operation
CodeBase-for-DBF copied to clipboard

Added .NET (VB & C#) Interfaces, C# Test, .NET reference guides, and …

Open phillipsawyer opened this issue 5 years ago • 31 comments

….NET example projects

The VB.NET / CSharp interface with documentation and example code files. interfaces/CSharp/Codebase.cs or interfaces/CSharp/Codebase.cs are the key interface files needed to use it with .NET. There's is quite a bit of difference between the two.

This is the latest & official .NET stuff and is hugely useful if you're developing with codebase in .NET

phillipsawyer avatar Aug 27 '20 06:08 phillipsawyer

Man, your pull request have missing files in C# exemple... Can you help me with that? I need to generate a x64 version from this dll.

phelipepalte avatar Oct 23 '20 13:10 phelipepalte

I'm not sure why the example is so poor. That's all they had in the archive.

The existing build is in the repo, c4dll.dll, which is used by myself and others in .NET works fantastic. If you would like to build a new DLL for some reason, I can only guide you to the C source code which is in the repo, and wish you luck.

The documentation is all there for C#/VB.NET which I have used with success.

phillipsawyer avatar Oct 24 '20 08:10 phillipsawyer

Can u help me, please? Because when I tried to import your dll in visual, I received a error;

phelipepalte avatar Oct 25 '20 06:10 phelipepalte

I can help you a bit if you provide me with an example and the error you're running into.

The interface which you use in .NET is located at CodeBase-for-DBF/interfaces/CSharp/Codebase.cs The VB.NET one which I actively use is in the interfaces/VB.NET folder

They are NOT written by me. It is an official interface that was kindly provided to me by the folks that wrote CodeBase despite it now being legacy unsupported software.

By the way, I'm just a programmer that uses Codebase.

phillipsawyer avatar Oct 25 '20 08:10 phillipsawyer

Image when I tried to add a reference to dll from your pull.

https://ibb.co/Q9SBnZv

When I tried to create Code4 cb = new Code4():

"Não é possível carregar a DLL 'c4dll.dll': Não foi possível encontrar o módulo especificado. (Exceção de HRESULT: 0x8007007E)" "Cannot load DLL 'c4dll.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

I throw the files in same level from my program.cs:

https://ibb.co/JnChZSt

Can you send me your dll?

phelipepalte avatar Oct 26 '20 12:10 phelipepalte

@phelipepalte you can’t add a direct reference to the dlls for codebase. They don’t have the correct interfaces to allow that and they’re not COM compatible. There is a code file you need to add that is the wrapper interface to codebase. I will look in my files for a c# one soon but an example of this is in VB.NET called codebase.vb which I’m sure can be converted with one of the online C# to VB.NET code converters. I’ll report back soon.

trevster344 avatar Oct 26 '20 12:10 trevster344

https://ibb.co/ypbjwYQ

When I try to open exemple proj, I'ts missing 2 files. Check above.

phelipepalte avatar Oct 26 '20 12:10 phelipepalte

Your links don’t appear to work for me. They all 404, possibly a privacy setting?

trevster344 avatar Oct 26 '20 12:10 trevster344

https://ibb.co/F7LTXDH

Try this.. unfortunately, the project is missing 2 files in VB too

phelipepalte avatar Oct 26 '20 12:10 phelipepalte

Go to my fork of the repository in my profile and go to VB.NET folder. I’ve added it there. Still looking for my c# equivalent.

trevster344 avatar Oct 26 '20 12:10 trevster344

I fixed the links.

phelipepalte avatar Oct 26 '20 12:10 phelipepalte

@trevster344 Thank you for your help.

What version of Visual Studio you've using for this?

phelipepalte avatar Oct 26 '20 12:10 phelipepalte

I am on the latest version of Visual Studio. I actively develop in VB.NET using .Net Framework 4.8+ and .Net Core

trevster344 avatar Oct 26 '20 12:10 trevster344

I see, so, you just copy the dlls to project level and call code4?

phelipepalte avatar Oct 26 '20 13:10 phelipepalte

Yes.

trevster344 avatar Oct 26 '20 13:10 trevster344

Trying your fork..

phelipepalte avatar Oct 26 '20 13:10 phelipepalte

Imports VB6 = Microsoft.VisualBasic.Compatibility.VB6

I having issue from this import, not found. You have VS 2005 too? I can't find how to install this

phelipepalte avatar Oct 26 '20 13:10 phelipepalte

You need to go to projects and add a reference to Microsoft.VisualBasic.Compatibility

trevster344 avatar Oct 26 '20 13:10 trevster344

"Microsoft.VisualBasic.Compatibility.* classes are obsolete and supported within 32 bit processes only" I think I can't find because my windows is 64 bit... =\

phelipepalte avatar Oct 26 '20 13:10 phelipepalte

This will get the project working but it doesn’t take much to convert the .vb not to use Microsoft.Visualbasic.Compatibility. Codebase does not come built for x64 and there are some who argue it isn’t truly x64 when you do compile it as such. I have an x64 build and while everything I have confirms it’s x64, I’ve not been able to get it to run yet. Do you have a working x64 build of codebase?

On the topic of Microsoft.Visual Basic.compatibility, I’ve long since believed most of that .NET code file is just a working but poor conversion from the original VB6 codebase module. I’ll see about converting it and putting it on my repo.

trevster344 avatar Oct 26 '20 13:10 trevster344

Man, I fixed the issue with import, but unfortunately I'm a C# programer.. =\

You have a exemple how call the Codebase?? (i tried CodeBase.d4open(1, "C:\folder\File.dbf"), but I get exception "An attempt was made to load a program with an incorrect format. (0x8007000B)")

phelipepalte avatar Oct 26 '20 13:10 phelipepalte

D4open will open a database file but it doesn’t initialize codebase. In Visual Basic you have to call code4init first. Call the equivalent for c#. I am not at my workstation yet so I can give more support yet. Soon however.

trevster344 avatar Oct 26 '20 14:10 trevster344

That error usually means you are mixing bitnesses (32 and 64). There is no such thing as 64-bit VB6. You can have 64-bit VB.NET, but you mentioned VB6 above. For VB6, your application must remain 32-bit, even when the Windows itself is 64-bit. Also, I believe that Codebase doesn't have correct code to properly run in 64-bit. There are many problems with casting wrong-sized integers to pointers, etc. Stick with 32 bit Codebase.

ScotBren avatar Oct 26 '20 14:10 ScotBren

Good news, I finally got sucess to use the dll.. (how? I don't know..)

I have installed so many things and work.. LOL

Now, I need to learn how check if the dbf is ok or have errors..

Thank for all help.

phelipepalte avatar Oct 26 '20 14:10 phelipepalte

More than likely you’re not running x64 however. Who compiled codebase x64 prior to you? Or was it you?

If you have the guides they tell you all you need to know. Be wary of code4error settings.

trevster344 avatar Oct 26 '20 15:10 trevster344

I just use your dll and run in my environment. I don't know why.. LOL Running in x64 project.

phelipepalte avatar Oct 26 '20 15:10 phelipepalte

What is the name of the dll you have in your project directory?

trevster344 avatar Oct 26 '20 16:10 trevster344

By the way @trevster344 I've got the official C# interface in my pull request and I would assume the same vb.net interface as you as well.

phillipsawyer avatar Oct 26 '20 19:10 phillipsawyer

By the way @trevster344 I've got the official C# interface in my pull request and I would assume the same vb.net interface as you as well.

Thanks! A lot easier to see from a desktop. Couldn't see it earlier but you're absolutely correct. I mostly just wanted to convey the library is best worked with from the wrapper.

trevster344 avatar Oct 26 '20 20:10 trevster344

In case it helps others:

  1. The c4dll.dll included in the source tree is 32-bit. You may need to add X86 to your project as the cpu=Any will be 64-bit in most situations. (e.g. VS 2022) If you have an architecture mismatch, the Code4 ctor will throw System.BadImageFormatException: 'An attempt was made to load a program with an incorrect format.
  2. Surprisingly, c4dll.dll depends on zlib.dll which is provided in the CodeBase source/ dir. If you don't include both dlls in your project output, the Code4 ctor will throw System.DllNotFoundException: Unable to load DLL 'c4dll.dll' or one of its dependencies: The specified module could not be found.

usrlocalben avatar Feb 27 '23 02:02 usrlocalben