How to use .c file in Visual Basic project? - vb.net

I need to convert C code to Visual Basic.
I have .c and .h files.
Are there some ways to use my .c file in Visual Basic Application? Application was created in Visual Basic 6.0.
Now I see only one way: convert the code manually. But it takes a lot of time because I never use VB before, so I need some time to learn the syntaxes.
I read some info about using .dll in VB. Maybe there are some ways, for example, create a .dll from .c and then use it in my application?..

How much C code do you have to work with? If it is short, then by all means convert it by hand. Good opportunity to learn VB if you will be working in that language anyway. If it is very large, compile to a standard DLL with exported functions, and just call it from VB.
(Added as answer from comment above)
Good addition from another comment: If you do decide that the best route is to compile the C code as a DLL and call it from VB6, you should read this Microsoft document on how to do it.

Related

I made a project in C++ CLI, But I can decompile it using a C# Decompiler

Is there any way, I can prevent my c++ cli project from being decompiled if someone uses a C# decompiler, because I tried to decompile the .exe i made in ILSpy and it showed my whole code, so is there any way I can prevent this?
Thanks
as ancient as this thread is, I ran across it with the same question, and a newish answer. Can't specify the minimum version for this one, but
[module:System::Runtime::CompilerServices::SuppressIldasmAttribute];
on top of each .cpp module did the trick for me:
I didn't investigate much further, yet.
Another useful thing is to add
#pragma unmanaged
to each .cpp that does not contain .net code.
You can
Use a .NET obfuscator.
Or
Only use C++CLI for the boundaries of your app which require to Interact with .NET. And implement your logic in a native C++ library.

vb.net: is it possible to import FreeImage.dll to vb.net?

I need to read\write tga files from vb,
I found TargaImage.dll, nice lib but it allows only read tga.
I found FreeImage, tryed to import it in vb, but it says:
FreeImage.dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
I think I have to use , but absolutly dont know anything.
help plz:)
From looking at the way the distribution works, you have two options:
First, you could call the functions in the DLL directly using <DllImport> attributes. This is going to require a lot of learning of how to make calls to unmanaged DLLs, passing the right values, etc. Which is why I suggest the second option.
The second option is, you can use the .NET Wrapper project that is included in the distribution. If you're using a version of Visual Studio that supports multiple programming languages, just add the wrapper project to your solution and reference the wrapper project from the project that needs to use it.
If you're using Visual Studio Express, you won't be able to add a C# project to a VB solution. I'd suggest downloading C# Express, compiling the wrapper project, and then adding the compiled DLL to your VB.Net project.

Porting a .bas file to vb.net

I'm working on some legacy VB5/VB6 code and need to convert a ".bas" file to vb.net.
I found several options
Compile the .bas file into a com dll and then reference and use it in my project. (For this I guess I would need vb5 or vb6 which I don't have at my disposal)
Copy and paste the contents of the file in to a new module in vb.net and then try solving the errors one by one.
The contents of the .bas file reference a particular dll.
The .bas file has mostly declarations consts, types, sub's and functions.
What would be the most elegant way of redoing this in vb.net. Is it as simple as option 2.
EDIT
I used VS2008 express and ran the code through the upgrade wizard it did the necessary conversion. and the .bas file was converted to .vb. I took that file and decided to rewrite other parts of the code, including some redoing of the converted .vb file.
Other questions related to this one are here.
Consider rewriting as an alternative. In my experience, this makes less work in the long run than either relying on an opaque COM library or using the VB6 migration wizard and picking up the pieces it spits out.
Depending on your knowledge of .NET, the rewrite of a single VB6 module shouldn’t take very long. If you are freshly starting with .NET then this may take longer but it will also provide good opportunities to learn .NET.
Microsoft provide guidance on what to do including an app that attempts to convert VB6 code to .NET
This includes both your solutions except 2 is helped by the converter.
It depends on how complex the VB6 code and what it does.
However if you are going to have to support and change the VB6 code it would probably be worth doing the conversion now.
There are a lot of advantages to converting to vb.net -- compatibility with future (and possibly current) systems and maintainability being the most important. The main advantage to leaving it as a dll would be to save development time, but this could backfire if there are future compatibility problems.
If the code is in a VB6 project now, or if it can be added to one, you can open the .vbp project file with vb.net and it will it asks if you would like to automatically convert it to vb.net. It does a pretty good job, exclusive of third party add-ons.

Can't add vb class to c# project in vs 2010

When I add my vb classes to my C# project in vs 2008 they are readily available to be used in my c# classes. But for some reason 2010 can't see them. I could be missing something simple but i couldn't make it work in the past hour. Any ideas?
Are you sure you had them included with action compile and not just action content?
CSharp and VB use two differnt MSBuild targets file and I've never heard of mixing them in the same project file. Different project types in the same solution - sure, but not what I think you are saying.
Of course it's a strange world so maybe someone will come by and suprise me with something I never thought possible outside of ILMerge after the build.
you can't mix 2 code languages. like you can add vb and vb, c# and c# but not vb and c# together.
If you do want to mix, use a code converter like c# - vb or something. Here is one to try instead of re coding it all again: Vb.net --> C# converter.
It may not be 100% working but at least you'll convert some code.

Need to convert C# to VB.NET

I have some C# source code that I got off the Internet and I want it in VB.NET. How would you convert it because I don't know C#.
I found multiple translators after performing a simple search, but this one looks kind of cool. No installation necessary!... though I have never used it.
Another way is compiling it to, dragging the assembly to Reflector and then decompiling it to VB.NET
If I recall correctly, you can have multiple source languages in the same project. They just have to be in different files. You should be able to call the c# class from a vb.net class without any major problems. This may not be the prettiest option, but it might work for your situation.
You can have a VB project in the same solution as a C# project, and use classes from either from the other, but you can't have both VB and C# source files compiled in the same project.