Q:

sine-tone generation with sin(double) fills out blocks of memory unexpectedly

I’m writing a code in c that outputs data in a file. The code generation (amplitude) function isn’t yet well defined. At compile it runs ok but the output isn’t what I expected. Even with dwVal=0 the output is the same : a string of ascending values and not a sine.
long dwData=200;
HGLOBAL hData=GlobalAlloc(GMEM_MOVEABLE, dwLength);
int wData=(int)GlobalLock(hData);//no cast to (int)

    for(int i=0;i<dwLength;i++){
        DWORD dwVal=16384*sin((double)i/20*pi);
        memset(&wData+i, dwVal, 2);
    };

//save data
    if (!PathFileExists(szName1))
        strcpy(szName1, "output.pcm");

FILE* file=fopen(szName1, "wb");
    for(i=0;i<dwLength;i++){
        DWORD j=fputc((int)&wData+i, file);
        if (j==EOF){
            cvar.mbsz("error writing", "titlu", j);
            return;
        };
    };
    fclose(file);

Please help me clarify what’s wrong in the first part (the sine generation) and how it should look like. Many thanks for your time.
EDIT
int *wData=(int*)GlobalLock(hData);//no cast to (int)

DWORD dwVal;
    for(int i=0;i<dwLength;i++){
        dwVal=16384*sin(pi/20*(long)i);
        wData[i]=dwVal;
    };

FILE* file=fopen(szName1, "wb");
DWORD j;
    for(i=0;i<dwLength;i++){
        j=fwrite(&wData[i], 1, 1, file);
        if (j==EOF){
            return;
        };
    };
    fclose(file);

Thank you MSalters. I tried to do some replacement here and there but can’t say it compiles. I’m a newby in C++, and I need it in C++… can you write down for me the for loop. If you agree with me, the dwVal variable isn’t necessary to be an array. dwLength is a finite length (200).
Thank you Michael Waltz for your observations!
double pi=3.1415926535;
long dwData=200;
HGLOBAL hData=GlobalAlloc(GMEM_MOVEABLE, dwLength);
long *wData=(long*)GlobalLock(hData);

long dwVal;
    for(int i=0;i<dwLength;i++){
        dwVal=16384*sin(i/20*pi);
        wData[i]=dwVal;
    };

//save data
    if (!PathFileExists(szName1))
        strcpy(szName1, "output.pcm");

FILE* file=fopen(szName1, "wb");
    for(i=0;i<dwLength;i++){
        DWORD j=fwrite(&wData[i], 2, 1, file);
        if (j==EOF){
            cvar.mbsz("error writing", "titlu", 0);
            return;
        };
    };
    fclose(file);

The way I close &Release objects and file is ok?

A:

You probably want something like this:
    DWORD dwLength = 200 ;
    HGLOBAL hData=GlobalAlloc(GMEM_MOVEABLE, dwLength);

    int *wData=(int*)GlobalLock(hData);

    for(int i = 0;i < dwLength; i++){
        wData[i] = 16384 * sin( (double)i / 20 * PI );
    }

You should learn some C basics before going on.

