Save to struct

Hi!

I have problem with:
1
2
3
4
5
6
7
8
9
struct MyStruct{
WCHAR my01[256];
WCHAR my02[256];
};

MyStruct My1;
wcsncpy(My1.my01,"Some text",256) //- It's ok
wcsncpy(My1.my02,"Some text",256) //- My1.my02 is NULL
wcsncpy(My1.my02,My1.my01,256) //- My1.my02 is NULL 


Any idea??
no. if only one of two identical lines works, the problem is somewhere else. can you post all of your code?
and don't make multiple threads about the same thing..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
struct SCITY
{
    int id;
    WCHAR name[51];
    WCHAR desc[256];
    WCHAR def[256];
};

........

BOOL CALLBACK DlgCity (HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
  SCITY scityTemp;
  BOOL getFile = FALSE;
  FILE *f = NULL;
  OPENFILENAME ofn;
  WCHAR bufToFile[32767];
 switch (Msg)
 {
  case WM_INITDIALOG:
  SendMessage(GetDlgItem(hwnd,IDD_EDITT1),EM_LIMITTEXT,(WPARAM)9,NULL);
  SendMessage(GetDlgItem(hwnd,IDD_EDITT2),EM_LIMITTEXT,(WPARAM)50,NULL);
  SendMessage(GetDlgItem(hwnd,IDD_EDITT3),EM_LIMITTEXT,(WPARAM)255,NULL);
  bufToText[0]=0;
  wcscat(bufToTex,_T("NO FILE"));
  SetWindowText(GetDlgItem(hwnd,IDD_LABEL1),bufToTex);
  break;

  case WM_COMMAND:
  {
   switch (LOWORD(wParam))
   {
    case IDOK:
    {
        ZeroMemory (&scityTemp, sizeof(scityTemp));
        if(!GetDlgItemText(hwnd,IDD_EDITT1,wchFromInt,10))//wchFromInt is a int
        {
            MessageBox (NULL, _T("NO ID"), _T("Warning"), MB_ICONEXCLAMATION);
        }else
        {
            if(SearchId(_wtoi(wchFromInt),'c'))MessageBox (NULL, _T("Unavailble ID"), _T("Warning"), MB_ICONEXCLAMATION);
            else{
            if(!GetDlgItemText(hwnd,IDD_EDITT2,scityTemp.name,51))//scityTemp.name have text
            {
                MessageBox (NULL, _T("No City name"), _T("Warning"), MB_ICONEXCLAMATION);
            }else
            {
                GetDlgItemText(hwnd,IDD_EDITT3,scityTemp.desc,256);//scityTemp.des have text
                scityTemp.id = _wtoi(wchFromInt); // have ID

                if(getFile){ //getFile is TRUE - MY FAIL GETFILE IS NOT TRUE <- because is not global variable <- THIS iS the ANSWER
                ///THIS NOT WORKS
                wcscat(scityTemp.def,L"Some Text");  //No have text
                }
MessageBox (NULL, scityaTemp.def, _T("Warning"), MB_ICONEXCLAMATION); //Nothing in text

//I save to file and nothing only NULL
....


Sorry but code is very large
Last edited on
Are you sure getFile is TRUE? I don't see you setting it..

Anyway, this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <windows.h>

struct SCITY{
    int id;
    WCHAR name[51];
    WCHAR desc[256];
    WCHAR def[256];
};

int main(){
    SCITY sc;
    ZeroMemory(&sc, sizeof(sc));
    wcscat(sc.def, L"Hello world");
    wcscat(sc.desc, L"....");
    MessageBoxW(0, sc.def, sc.desc, MB_OK);
    return 0;
}
works fine.

One way to find the problem is to remove irrelevant parts of code until it starts to work.
Topic archived. No new replies allowed.