C++ DLL # BEGINNER QUESTION #

can someone help me solve my problem. I have a C++ program and i created a DLL out of it.

I have another C# forms application, and i added the DLL as 'add reference'. when i double click on this DLL, i get the 'Object Browser' and when i expand the '+' sign i don't see any of my member functions that i wrote in it.

example.h


#
1
2
3
4
5
6
7
8
9
10
11
12
13
pragma once

using namespace System;

namespace example {

	public ref class Class1
	{
	public:
		// TODO: Add your methods for this class here.
		 int main1(void); 
	};
}


example.cpp

1
2
3
4
5
6
7
8
#include "stdafx.h"
#include <stdio.h>

int main1( void ) {

printf("Hi !! ");
}


The above is a C++/CLL project (and i use Windows Vista, MS visual studio 2008)

Now i need to access this main1(), from the C# Main() method. can some one please tell me how i could do this.
If you created your Dll in unmanaged code, you can't add it as a reference. Add reference is just for Dlls written in managed code.
you can use DllImport attribute to import unmanaged dlls.
BTW, you should use __declspec(dllexport) before your function declaration and extern "c" around your function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include "stdafx.h"
#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

int __declspec(dllexport) main1( )
{
   printf("Hi !! ");
}

#ifdef __cplusplus
}
#endif 
Topic archived. No new replies allowed.