Using SPSS IO 32 DLL

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Using SPSS IO 32 DLL

Georg Maubach-2
Using SPSS IO 32 DLL

Hi All,

for a project I need to use the SPSS IO 32 DLL that is the SPSS developer C API. I managed to open a dataset for writing as well as for reading (function spssOpenWrite() and spssOpenRead returned "0" = Success). The dataset is encoded with "cp1252".

When calling the functions spssGetVarLabel() and spssSetVarLabel() with the required parameters I always get return code 12 = variable not found. The variable "testVar1" exists in the dataset.

--- cut ---
#include "stdafx.h"
#include "stdlib.h"
#include "c:\data\SPSS_IO_Dev_Module\IO_Module\spssdio.h"

void func()
{
        int fH; /* file handle */
        int error; /* error code */

        error = spssOpenWrite("c:\\temp\\datasets\\dataset1.sav", &fH);

        if (error == 0)
        {
                /* fH is a valid handle; process and */
                printf("Dataset successfully opened!\n");

                // Signature of spssSetVarLabel in documentation of SPSS IO 32 DLL:
                // spssSetVarLabel(int handle, const char *varName, const char *varLabel)
                error = spssSetVarLabel(fH, "testVar1", "Test"); // returns error code 12 = variable not found
                printf("spssSetVarLabel Return: %i \n", error);
               
                // Signature of spssGetVarLabel in documentation of SPSS IO 32 DLL:
                // spssGetVarLabel(int handle, const char *varName, char *varLabel)
                char *varLabel;
                varLabel = (char *) malloc ( 121 * sizeof(char) );
                error = spssGetVarLabel(fH, "testVar1", varLabel); // returns error code 12 = variable not found
                printf("spssGetVarLabel Return: %i \n", error);
                printf("varLabel nach Ă„nderung: %s \n", &varLabel);
               
                /* close file */
                error = spssCloseWrite(fH);
        }
        else
        {
                /* Handle error*/
                printf("ERROR: Failed to open dataset!");
        }
}
void main ()
{
        func();
        getchar(); // Show console output until key is pressed
}
--- cut ---

Do I do something generally wrong? If not, what could cause the problem?

Best regards

Georg