I have a dll that I wrote and a driver program to call that dll. Both the programs were written in VC++ 2008 express edition. The program takes in 2 strings as a command line argument and passes it to the dll which prints the 2 strings in the standard output. The problem that I have is when I pass the 2 strings and execute the program I get the following

Debug Assertion Failure
Expression: _CrtIsValidHeapPointer(pUserData)

This error also occurs only for certain command line arguments such as
"C:\Test Folder\Test Folder" "C:\Test Folder" or
"Winter Spring Summer Fall" "Seasons"

If the command line arguments were as follows
"Winter" "Spring"
the program executes without any error.

Also I would like to point out that while compiling both the dll and the exe, I used the following flag for the Code Generation under the project properties.

Runtime Library: Multi-threaded Debug (/MTd)

If I change the Runtime Library to Multi-threaded Debug DLL (/MDd), the program works fine for all the above command line arguments.

Please do not tell me that I should be using the Multi-threaded Debug DLL (/MDd). It is for some reason I need to use Multi-threaded Debug (/MTd).

I am also providing you the code for the dll and the driver.


#include <string>
using namespace std;

#ifndef HEADER_H
#define HEADER_H

#ifdef EXPORT

#define DLL_EXPORT	__declspec( dllexport )


#define DLL_EXPORT	__declspec( dllimport )


extern "C" DLL_EXPORT int StringMani(string a, string b);



#include <iostream>
#include <string>
#include "CreateDLL.h"

using namespace std;

extern "C" int StringMani(string a, string b)
	char	*one,

	int	len1,

	len1	=	a.length() + 1;
	len2	=	b.length() + 1;

	one	=	new char[len1];
	two	=	new char[len2];

	strcpy(one, a.c_str());
	strcpy(two, b.c_str());

	cout << "a is: " << one << endl;
	cout << "b is: " << two << endl;

	delete[] one;
	delete[] two;
	return 1;


#include <iostream>
#include <string>
#include "CreateDLL.h"
#include <windows.h>

using namespace std;

int main(int argc, char* argv[])
	int ret_val;
	string	a,

	a	=	argv[1];
	b	=	argv[2];


	int(*fn)(string, string);
	hDLL	=	LoadLibrary("CreateDLL.dll");

	if (hDLL)
		fn	=	(int (__cdecl *)(string, string)) GetProcAddress(hDLL, "StringMani");

		if (fn)
			ret_val = fn(a, b);

Thanks in advance

What do you mean by code is not formatted? The code is between CODE tags

Your code is almost unreadable.

Are you on crack? The code is both consistent and intelligently formatted. The only truly odd thing I can see is a tab on both sides of the assignment operator, but that's hardly enough to cause one to trip up when reading.

This article has been dead for over six months. Start a new discussion instead.