how do i load a string out of a string table by its id number??? NO MFC!!!!
Printable View
how do i load a string out of a string table by its id number??? NO MFC!!!!
Code:#include <windows.h>
#include <tchar.h>
#include <string>
using namespace std;
typedef std::basic_string<TCHAR> tstring;
tstring LoadResString(UINT uID, HMODULE hMod) {
TCHAR pcBuf[1025];
LoadString((hMod ? hMod : GetModuleHandle(NULL)), uID, pcBuf, 1024);
return pcBuf;
}
help, it says theres no acceptable conversion
Bloody non-portable-Unicode-aware Philistines :rolleyes:Ignore the other one completely :rolleyes:Code:string LoadResString(UINT uID, HMODULE hMod) {
char pcBuf[1025];
LoadStringA((hMod ? hMod : GetModuleHandle(NULL)), uID, pcBuf, 1024);
return pcBuf;
}
it still isnt working, heres what im doing
pcString = LoadResString(id, hInst);
error D:\C++\Vbdll2\stringdll.cpp(20) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)
*choke* *gag*
Oooopsie ;)Code:string x = LoadResString(IDS_MYSTRING, hInst);
sorry with the errors, got a nother one, if you didnt know im new at c++ :D ,,please clarafy how to use LoadResString; i want the string LoadResString returns to be put into pcString so it can be sent to my vb app ( this is a dll project)
void __stdcall GetString(char *pcString, long id)
{
string pcString = LoadResString(id, hInst);
}
error C2082: redefinition of formal parameter 'pcString'
If you want to use it from VB then why not call the LoadResStringA API function on its own from VB?
whats LoadResStringA ?
how?
:eek:
LoadStringA :) Typo there :(
It's the actual API function you call.
nevermind i undersstand
how do i convert this; LoadStringA((hMod ? hMod : GetModuleHandle(NULL)), uID, pcBuf, 1024) to vb??
VB actually has a built-in function for this:VB Code:
Dim sThing As String sThing = LoadResString(101) ' Or any other valid ID
nooooooooooooooooooo i want to call it from the dll!
www.vbapi.com should have a definition/example for this.
i would use a vbdll but creating activex doesnt work on my win2000, Pleeese Pleassssssseeee can you make me a c++ dll that returns the specifyed res string to the vb app please, ill do any thing for you!
Is the resource stored in the DLL or the EXE?
a win32 dll , the res string table is in the dll,
VB Code:
Private Declare Function LoadStringA Lib "kernel32" (ByVal hInstance As Long, ByVal uID As Long, ByVal lpBuffer As String, ByVal nBufferMax As Long) As Long Private Declare Function LoadLibraryA Lib "kernel32" (ByVal lpFileName As String) As Long Private Declare Function FreeLibrary Lib "kernel32" (ByVal hModule As Long) As Long Private Sub Form_Load() Dim hMod As Long Dim sString As String hMod = LoadLibraryA("the_dll") sString = Space(255) LoadStringA hMod, 101, sString, 255 FreeLibrary hMod End Sub
vb error = cant find dll entry point loadstringA in kernel32
Umph...sorry I just typed that straight. Try user32 instead.
MUHAHAHAHA IT WORKS!!!! Thx i spend over 12 hours strait workin on trying to load a res string from a c dll! thx a million
No problem. Friendly hints for next time:
1. State your entire problem clearly in the first post
2. Browse around MSDN, vbapi.com, vbworld.com
:)
can the code you posted be applyed to bitmaps, icons, custom resources??? if so how?
The LoadImage function (actual name: LoadImageA) works in the same sort of way. PlaySound will accept the value returned from LoadLibrary too.