-
Returning strings?
I am using DevC++ and I am trying to write a dll. I am using the following code but I get this error.
Code:
C:Dev-Cppc++ dll string$Makefile.win [Build Error] No rule to make target `C++_DLL_STRINGprivate.rc', needed by `C++_DLL_STRINGprivate.res'. Stop.
dllmain.cpp
Code:
/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>
DLLEXPORT string returnstring(void);
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
/* Returns TRUE on success, FALSE on failure */
return TRUE;
}
dll.h
Code:
#include <cstdlib>
#include <iostream>
#ifndef _DLL_H_
#define _DLL_H_
#if BUILDING_DLL
# define DLLEXPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
using namespace std;
DLLEXPORT string returnstring(void)
{
string my_string("hello big world");
return my_string;
}
#endif /* _DLL_H_ */
untitled1.rs(needed for program I am using the dll with)
Code:
#include "dll.h"
STRINGTABLE
BEGIN
{
1 "returnstring%[s%returnstring%"
}
Why do I get this error and how do I fix it.
-
Can you post the Makefile? It's complaining that it can't find C++_DLL_STRINGprivate.rc, which it needs to build C++_DLL_STRINGprivate.res, which it probably needs to build C++_DLL_STRINGprivate.obj, which is supposed to be part of the DLL. Nothing to do with your actual code.
-
Yea here it is.
Code:
# Project: C++ DLL STRING$ # Makefile created by Dev-C++ 4.9.9.2 CPP = g++.exe CC = gcc.exe WINDRES = windres.exe RES = OBJ = dllmain.o $(RES) LINKOBJ = dllmain.o $(RES) LIBS = -L"C:/Dev-Cpp/lib" --no-export-all-symbols --add-stdcall-alias INCS = -I"C:/Dev-Cpp/include" CXXINCS = -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" BIN = "C++ DLL STRING$.dll" CXXFLAGS = $(CXXINCS) -DBUILDING_DLL=1 CFLAGS = $(INCS) -DBUILDING_DLL=1 RM = rm -f .PHONY: all all-before all-after clean clean-custom all: all-before "C++ DLL STRING$.dll" all-after clean: clean-custom ${RM} $(OBJ) $(BIN) DLLWRAP=dllwrap.exe DEFFILE="libC++ DLL STRING$.def" STATICLIB="libC++ DLL STRING$.a" $(BIN): $(LINKOBJ) $(DLLWRAP) --output-def $(DEFFILE) --driver-name c++ --implib $(STATICLIB) $(LINKOBJ) $(LIBS) -o $(BIN) dllmain.o: dllmain.cpp $(CPP) -c dllmain.cpp -o dllmain.o $(CXXFLAGS)
-
dll.h needs to #include <string>
-
Whoa, where did the newlines go?