I am trying to create a dll project using VS2005 (C++.NET). It is going to be used to access a database to store records w/o having to know how to actually create records (i.e. just pass info, and the dll classes will create a row in db).

I want to be able to use a String as a pass parameter but I am getting the following error:
""__declspec(dllexport) cannot be applied to a function with the __clrcall calling convention"

I have read some stuff on /clr option, managed and unmanaged stuff but its not very clear. I have also tried to create the project as a Win32 dll and as a CLR dll. What is the proper way to create a dll project that can accept the String type as a pass parameter (and return a String if necessary would also be nice).

Here is what I have so far. Obviously it doesn't actually insert anything into the db yet, just want to get the basics going first.

myApp.h:

#include <stdexcept>
#using "system.dll"
#include <string>
using namespace std;
using namespace System;

namespace myAppClass
{
	class myApp
	{
	public:
		//Returns info msg
		static __declspec(dllexport) int InsertMsg(String^ myTable);
	};
}

myApp.cpp:

#include "myApp.h"
#include <stdexcept>
#using "system.dll"
#include <string>
using namespace std;
using namespace System;

namespace myAppClass
{
	int myApp::InsertMsg(String^ myTable)
	{
		if (myTable == "")
		{
			throw new invalid_argument("Table name cannot be blank!");
		}

		return 0;
	}
}

Recommended Answers

All 2 Replies

static __declspec(dllexport) int InsertMsg(String^ myTable);

Why dont you add __declspec(dllexport) to the class instead?
Why do you need ^ ? (String^ myTable)


My Log class in Dll works fine using strings in functions :) And those two things i mentioned above, seems to be the onlything generally different.

First, you are trying to use managed code constructs such as String^ in an unmanaged code. Use char* instead. Let me know if it works.

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.