I am creating DLL using VC++ - Console application..

I am writing it for crating a new file... I am using Createfile function for this. but facing below error...

error C2733: second C linkage of overloaded function 'CreateFileW' not allowed

Below is my .CPP file from the project..

#include "stdafx.h"
#define DLL extern "C" __declspec(dllexport)
/*
//file handle
HANDLE hFile;
//something to contain the number of bytes read
DWORD dwNumWritten;
//a boolean test variable, to test for success of reads
BOOL bTest;
//a buffer… can actually be of any type
DWORD dwBuffer[256];

hFile = CreateFile("D:\\myfile.txt", GENERIC_WRITE, FILE_SHARE_WRITE,
                NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
*/

DLL int CreateFile(char *path)
{ [COLOR="Red"]facing error at this line[/COLOR]
int i;
HANDLE hPort = CreateFile(TEXT("COM1"), GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
return i; 
}

Because you're using C linkage, you cannot create overloaded functions. There already is a function CreateFile, so you can't write another one. Rename your function DLL int CreateFile(char *path).

Thanks for solution

Because you're using C linkage, you cannot create overloaded functions. There already is a function CreateFile, so you can't write another one. Rename your function DLL int CreateFile(char *path).

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.