What is the best way to put a DLL written in C into a VB.NET (Express Edition 2010) project? I have the declarations for the external functions locating absolute paths right now like so:
C:\Users\Kyle\Documents\Pelles C Projects\ROBOLIB\ROBOLIB.dll
Because Visual Basic creates so many different directories the program could be running from (Debug, Release, Publish). Is there any way I could tell VB.NET to some files into the program's directory? Or should I somehow customize the installer so it puts the DLLs I need in a specific location?
You can add the DLL to your project (either per Drag'n'Drop or right mouse click -> Add -> Existing Element). If you right click the file and choose properties, you can define "Copy to output directory".
Of course, you should ensure that the installer (in case you create one) copies the files.
Related
To All,
I haven't used a Visual Studio in quite a few years, and don't remember what version I had used. I created 15-20 libraries and 30-40 utilities - all in C.
I recently decided that I wanted to enhance some of the libraries and utilities and acquired Visual Studio 2010. I open an existing project (.dsw) and I get a popup that says "The project ' must be converted to the current ... Convert and open this project?' I click on Yes. I then get a popup that says "A file with the same name ... already exists on disk. Do you want to overwrite the project and its imported sheets?' Again I say Yes.
I go along my way and make a bunch of changes to the project. I click on "Save All." I then close the project and when I reopen, it is like I didn't change anything! I get the same popups again!
I've check the permissions on the directory and files and they should be writable. I have SCOURED the net trying to find out what I am doing wrong to no avail.
Any helpful pointers would be greatly appreciated!
TIA,
je
.dsw extension was used by Visual Studio 6, Visual Studio 2010 project files have extension .vcxproj. The conversion process mentioned in your question creates those new project files. Open them instead of old .dsw
I am working on a multi-solution project on VS 2013 in C (I must use C for this project). I implemented one "Common" project that I intended to use as a reference in another project. So I have one solution with a common.h and a matching common.c source in which I implemented all the common functions.
I now created a new "Application" project (inside the current one, so I now have 2 solutions) which does many things, and use the functions that are already implemented in the common.c file (that is in the "Common" solution). So I have a app.h file with a matching app.c source. I changed the settings so that the "Application" project will include the "Common" project.
However, when I run the "Application" solution (only it since the "Common" project is only used as a reference without a main function) I receive an error telling me that there is no reference to the functions in common.h.
I looked online for a solution and someone said that I should just copy the common.c to my "Application" project, however this is a very bad solution for me since I want to have multiple applications that all of them use the "Common" project.
How can I solve it?
You shouldn't have to copy any files to make this work. Right-click on your solution at the top of the Solution Explorer window. Choose Add -> Existing Project from the context menu. Find the project file for your "Common" project. It should show up in the list of projects for your solution.
Right-click your "Application" project in the solution explorer and choose "Properties" from the context menu. In the property pages window, go to "Common Properties". Click the "Add New Reference..." button. In the "Add Reference" window, go to the "Solution" tab, and then click the checkbox for your "Common" project. Click "Ok".
Now your "Application" project has a reference to your "Common" project. You can also open common.c and common.h from inside your new solution, and any changes will automatically be applied to all other solutions that reference it, because they are the original files and not mere copies.
The above method assumes that the output of your Common project is a DLL. Visual Studio (for whatever reason) won't automatically copy statically linked library (.lib) files. You can of course link against them, but adding a reference won't work. You will need to go to the properties page for your "Application" project, go to the linker -> input tab, and edit the Additional Dependencies line. You can also add the directory containing common.h to your Additional Include Directories under the C/C++ tab.
Either way, my opinion is that merely copying the files is a bad idea unless you're using modules in source control (e.g. Git modules or SVN externals) to manage dependencies.
I want to use a DLL written in C in a VB project such that the DLL will be copied to the output directory.
I earlier asked this question here and got an excellent answer:
VB.Net using C DLL
All you have to do is go to the Project menu and "Add Existing Item". This works great if you copy any updates to your DLL into the project folder. Now I have a new project, and I put my C project folder inside the Visual Basic project folder in hopes that Visual Basic would fetch the DLL from that folder and copy it to the output directory. Oh no, they would never make it that easy. Adding an existing item copies that file to the project folder. So now it always fetches an old copy of the DLL unless I manually fix this, which I do not want to. How can I make Visual Basic honor my wishes?
When you do the "Add Existing Item..." the Add button has two options, one that will add a Link to an existing file and not copy to your project, but it will copy to the build output.
HY,
Know someone how can i add a assembly to GAC and Add reference dialog automatically in same time.
I have a setup project which i set him to add the assembly automatically to GAC, but i can`t add that in add reference dialog from visual studio 2010. I search on the internet but i didn't found how to do it.
The idea is that i have a project template from a project which use two assembly. I want to placed the 2 assembly in GAC when he is running the setup of the framework which i give to him.
Thanks.
Your English is hard to decode but it sure sounds like you are on the wrong track with this. The GAC is a deployment detail. You'll have no trouble putting an assembly in the GAC with your Setup project.
That assembly does not belong in the GAC on your dev machine. To add the reference, simply use the Add Reference dialog and use either the Project or Browse tab.
If your assembly is intended to be used by another programmer so that she can use your product in her own project then you need to deploy your assembly twice. It needs to go into the GAC and a copy of the assembly needs to go in a dedicated folder so your client can add the reference to it in her own project. The c:\program files\reference asssemblies directory is a good place to put it.
Putting it in the GAC for her is optional btw, it isn't that commonly done. I think most programmers would prefer that you don't do this, unless you work for a Big Company that needs to automatically distribute security updates. Putting it in the GAC just makes it harder for your client to write her own Setup project since she has to run yours first.
tribanp
I've created a sexy visual studio extension that will help you to achieve your goal. Muse VSReferences will allow you to add a Global Assembly Cache reference to the project from Add GAC Reference menu item.
Regards...
Muse Extensions
I would like to do some C development in Windows environment using Visual Studio 2010. There are a few similar questions on this topic, but they are all based on that you are creating a Win32 console application, and a C++ project.
How can I do C development using only .c and .h files as I do in Unix? without creating a C++ projects containing tons of files.
It is possible to do C compiling with the cl compiler from outside of Visual Studio 2010, see Walkthrough: Compiling a C Program. But how can I do this compilation and execution/debugging from inside Visual Studio 2010?
UPDATE
I have tried to create a C++ project (Win32 Console Application) and only add .c files to it. It works but it creates tons of files.
I have tried with a C++ project (Empty project), but it also created a lot of project files.
Basically what I want is to only create .c and .h files, use the cl compiler, and use Visual Studio 2010 as a text editor. And use a command to compile from the text edior, but it seems like I have to compile in a command prompt.
File → New → Project...
Under C++, choose Empty Project. If you want to minimize the number of folders created, uncheck the box to Create Directory for Solution. Give the project a name and location and click OK.
In the Solution Explorer for the new project, right click Source Files and select Add → New Item.
Choose C++ File (.cpp), and give it a name like SomeName.c. Make sure to specify the .c extension. Add the following code:
int main(int argc, char** argv)
{
return 0;
}
If necessary, disable Microsoft extensions to the C language by right clicking the project and selecting Properties. Select All Configurations at the top of the dialog. Then go to C/C++ → Language → Disable Language Extensions: Yes.
Visual Studio will create the following files for your project. Just get used to having them there. Do not check items with a * into source control.
ProjectName.sln
ProjectName.sdf*
ProjectName.suo*
ProjectName.vcxproj
ProjectName.vcxproj.user*
ProjectName.vcxproj.filters
somename.c
If you compile a file that has the .c extension, VS will use it's C compiler. However, you should be aware that said C compiler isn't C99 conformant (or even C89 for some cases, if I remember correctly). Visual Studio is not really a C compiler, it's C++ mostly. You will have to use a C++ project and simply include .c files.
VS actually has a very capable C compiler, somethng that people overlook all too often. The above answers will point you in the right direction, but it's by no means low quality like I've heard people say in the past.