CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: String resource

  1. #1
    Join Date
    Oct 2001
    Posts
    32

    String resource

    Hi,
    I was wondering if there's a way to create a string resource using a manual Win32 command. I don't want to use an .rc file in my project, and I need to get an identified for a string, that can be loaded through LoadString. Normally, I would define such a string in the string table, but I haven't found a way to do it manually.
    Thanks

  2. #2
    Join Date
    Nov 2001
    Posts
    323
    How about this: I usually put this in StdAfx.h, but you can put this below your include statements
    Code:
    #define MY_STRING          "This is my constant string"
    #define PING_SERVER      "\\\\MyFileserver"
    You won't be able to do LoadString, but you won't need to, just use MY_STRING wherever you need the string.

    I hope this helps,

  3. #3
    Join Date
    Oct 2001
    Posts
    32
    No, I have to use LoadString. I have to get an identifier for my string. Any ideas on how to do this?

  4. #4
    Join Date
    May 2002
    Location
    Poland
    Posts
    48
    Why don't you just use a simple array of structs containing int id nad char* string pairs?
    regards,
    MiMec

  5. #5
    Join Date
    Oct 2001
    Posts
    32
    Because a simple array won't enable Win32 to load the string from memory according to its ID. There should be some Win32 command to do this.

  6. #6
    Join Date
    Jun 2002
    Posts
    75
    Hi,

    I think I need to ask the question : why don't you want to use a resource script? (OR) why do you have to use LoadString.

    I only ask because LoadString is designed specifically to get strings out of your resource area. Since you don't want to use the resource area why use LoadString?

  7. #7
    Join Date
    Oct 2001
    Posts
    32
    Because I'm trying to code a portable wrapper for some features in MFC, and therefore I can't use an .rc file. Since CSingleDocTemplate takes a string ID in its constructor, and I don't use a resource file, I have to create that string table manually.

  8. #8
    Join Date
    Jun 2002
    Posts
    75
    Aahhh, I see. Well, I think trying to "fool" MFC into loading a string will probably be the hardest route for you to take.

    Hows about this : instead of using CSingleDocTemplate, build your own by subclassing CDocTemplate. This way you can have your own constructor that doesn't take a resource ID. I've only had a quick look but it seems possible at first glance.

    Hope this helps,
    swg

    p.s. what happens if you pass 0 as a resource ID? Does it fall over? If not you're OK because all of the string related member variables of CDocTemplate are public so you can just set them to whatever you like.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured