Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

phillipsawyer
Copy link

….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

@phelipepalte
Copy link

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.

@phillipsawyer
Copy link
Author

phillipsawyer commented Oct 24, 2020

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.

@phelipepalte
Copy link

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

@phillipsawyer
Copy link
Author

phillipsawyer commented Oct 25, 2020

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.

@phelipepalte
Copy link

phelipepalte commented Oct 26, 2020

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?

@trevster344
Copy link
Contributor

@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.

@phelipepalte
Copy link

phelipepalte commented Oct 26, 2020

https://ibb.co/ypbjwYQ

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

@trevster344
Copy link
Contributor

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

@phelipepalte
Copy link

https://ibb.co/F7LTXDH

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

@trevster344
Copy link
Contributor

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.

@phelipepalte
Copy link

I fixed the links.

@phelipepalte
Copy link

@trevster344 Thank you for your help.

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

@trevster344
Copy link
Contributor

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

@phelipepalte
Copy link

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

@trevster344
Copy link
Contributor

Yes.

@phelipepalte
Copy link

Trying your fork..

@phelipepalte
Copy link

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

@trevster344
Copy link
Contributor

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

@phelipepalte
Copy link

"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... =\

@trevster344
Copy link
Contributor

trevster344 commented Oct 26, 2020

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.

@phelipepalte
Copy link

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)")

@trevster344
Copy link
Contributor

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.

@ScotBren
Copy link

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.

@phelipepalte
Copy link

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.

@trevster344
Copy link
Contributor

trevster344 commented Oct 26, 2020

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.

@phelipepalte
Copy link

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

@trevster344
Copy link
Contributor

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

@phillipsawyer
Copy link
Author

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.

@trevster344
Copy link
Contributor

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.

@usrlocalben
Copy link

usrlocalben commented Feb 27, 2023

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.

@phillipsawyer
Copy link
Author

zlib was added later on in codebase's life and I believe there are some configuration options to utilize compression as storage-saving measure. I have been bitten by not having the zlib.dll dependency as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants