hi all..

Im using visual studio 2005.
I want to import log4cxx.dll to my project.
if you know how to do this please reply to this thread

thank you
wijitha

If you do not have the *.lib that normally comes along with dlls then you can use LoadLibrary() to load the dll into memory, then GetProcAddress() to get a pointer to a function in the dll. See this for details.

In Solution Explorer you can also use Add reference to add a dll to your project.

In Solution Explorer you can also use Add reference to add a dll to your project.

Does that work with ordinary c++ programs? Or just CLI managed programs?

Does that work with ordinary c++ programs?

I think this will only work in Visual Studio...

I think this will only work in Visual Studio...

Visual Studio is a compiler, not a language. What I am asking is do you have to create a CLI managed project to use that feature. I tried with a normal c++ program but could not add a reference that way. I don't normally write managed code.

I tried to add the dll by reference->Add new Reference. then, it shows a pop up window called add reference. There I cant do nothing to add a dLL. Here I'm using visual c++ 2005.

wijitha

I tried to add the dll by reference->Add new Reference. then, it shows a pop up window called add reference. There I cant do nothing to add a dLL. Here I'm using visual c++ 2005.

wijitha

Yup, same here. Go back and re-read my previous post about LoadLibrary()

Visual Studio is a compiler, not a language.

Visual Studio is a development environment in wich you can have compilers for C++, C#,J++,Visual Basic and others. I use Visual C# most of the time and I can write managed and unmanaged code with it. But I like managed code. I can't count the hours I have wasted in C++ on figuring out why my handles and pointers where already in the "twilight zone" when they shouldn't be...

it shows a pop up window called add reference. There I cant do nothing to add a dLL. Here I'm using visual c++ 2005.

I have no problem with it, I can even browse for .exe, .lib files, besides .dll files.
The selected file will appear in solution explorer in a folder called references.
But if it doesn't work, follow the advice of Ancient Dragon.

Visual Studio is a development environment in wich you can have compilers for C++, C#,J++,Visual Basic and others. I use Visual C# most of the time and I can write managed and unmanaged code with it. But I like managed code. I can't count the hours I have wasted in C++ on figuring out why my handles and pointers where already in the "twilight zone" when they shouldn't be...
.

As I suspected, you are using VS to write managed code, not unmanaged plain-jane c++ code as most of the rest of us do. Nothing wrong with that, but you provide a solution to a different problem.

I was answering a question about visual studio 2005.
You are right, writing unmanaged plain-jane c++ code(nothing wrong with that!) is not my cup of tea anymore...
But can you use VS to write really native, unmanaged code? I wonder.

But can you use VS to write really native, unmanaged code? I wonder.

Yes, it is definately possible for C/C++. C#, probably not, but we are not discussing C# in this board.

Thanks for your answers anyway. I would not dare to discuss C## in this forum.
Happy programming!

I faced a lot of trouble to figure this out. So I'm going leave the details to relieve the noobs like me from tiresome searching...

There are other ways but this one worked fine for me.

Step 1(Create the Win32 DLL):

1. File->New Project->VC++->Win32 Project->Give it a name(say xyz) & click OK
2. A new config window pops up...
Set: Application Type=DLL
Additional Options=Empty Project
Finish
3. In Solution Explorer in addition to the source cpp file, add one .def under Source Files. It should have the same name as the project i.e xyz.def.

(a) In the cpp file rename the function definition & declaration as

void [B]__declspec(dllexport)[/B] __stdcall fun(int a,char b,...){...}

(b) In the .def file add the following code

LIBRARY "xyz"
EXPORTS 
    fun

4. Build->Configuration Manager
Configuration: Release, Platform: Win32

5. This step is optional(required when strings are involved etc..)
Go to Project Properties->Linker->Input->Additional Dependencies
Add ws2_32.lib, you don't have to locate it.

6. Build


Step 2(Create a VB Application for Testing):

1. Locate the path of the DLL released say "C:\...\xyz.dll"

2. Inside the vb file containing the event handler, add the following declaration(outside the definition of event handler)

Private [B]Declare Function fun Lib "C:\...\xyz.dll"[/B] (arg list) As ...

Now you can happily call the exported function.

note: As it has been pointed out before, in unmanaged scenarios you can't add references to dll from the IDE itself, it'll throw you an error, this is the hard way.

I had problems with Visual C++ finding the .dll files. I solved it by going to my windows environment variables and setting the path to point to the place where I had the .dll file. Once I rebooted my Visual C++ IDE, it worked fine.

Good Luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.