Returning strings?

This is a discussion on Returning strings? within the C++ Programming forums, part of the General Programming Boards category; I am using DevC++ and I am trying to write a dll. I am using the following code but I ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    9

    Question 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.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    9
    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)

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    dll.h needs to #include <string>

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Whoa, where did the newlines go?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Does returning newly-declared strings cause leaks?
    By Anvilsmith in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2008, 12:01 PM
  2. Returning Strings
    By Overload in forum C++ Programming
    Replies: 14
    Last Post: 07-29-2004, 08:05 PM
  3. Please help with String class, returning strings
    By skanxalot in forum C++ Programming
    Replies: 4
    Last Post: 09-24-2003, 11:48 AM
  4. correct way of returning strings
    By marsface in forum C++ Programming
    Replies: 5
    Last Post: 06-11-2003, 11:33 AM
  5. returning strings
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 09-06-2001, 11:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21