0

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;
	}
}
3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by yavorski
0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.