Struct Size

I am trying to determine the size of a structure, as in byte
size, not structCount() before I include it in an error handling
email. Does anyone have a solution that does this?
Thanks.

This is an interesting problem.
Would something like this get you close enough...
<!--- create the structure object --->
<cfset myStruct = StructNew() />
<!--- add one item with a data-type of simple value
--->
<cfset StructInsert(myStruct, "my_key", "my_value") />
<!--- add another with a data-type of array --->
<cfset myArray = ArrayNew(1) />
<cfset ArrayAppend(myArray, "another_value") />
<cfset StructInsert(myStruct, "another_key", myArray)
/>
<!--- number of bytes as a string --->
<cfset len = ArrayLen(myStruct.toString().getBytes())
/>
Good luck!

Similar Messages

  • Call library with struct as parameter - several problems

    Hi everyone,
    I'm trying to send a MIDI sysex message to a midi device through winmm.dll using MidiOutLongMsg. I have trouble figuring out how to pass the parameters right.
    I need to call three functions (midiOutPrepareHeader, midiOutLongMsg, midiOutUnprepareHeader), all of them having the same form
    MMRESULT midiOutPrepareHeader(
    HMIDIOUT hmo,
    LPMIDIHDR lpMidiOutHdr,
    UINT cbMidiOutHdr
    where HMIDIOUT hmo is a handle that I have already. Troubling me are the other two parameters. cbMidiOutHdr is the size (in bytes) of the struct lpMidiOutHdr. This is a struct of the form
    typedef struct {
    LPSTR lpData;
    DWORD dwBufferLength;
    DWORD dwBytesRecorded;
    DWORD_PTR dwUser;
    DWORD dwFlags;
    struct midihdr_tag far * lpNext;
    DWORD_PTR reserved;
    DWORD dwOffset;
    DWORD_PTR dwReserved[4];
    } MIDIHDR;
    (Struct: http://msdn2.microsoft.com/en-us/library/ms711592.aspx
    PrepareHeader http://msdn2.microsoft.com/en-us/library/ms711634.aspx
    SendMessage http://msdn2.microsoft.com/en-us/library/ms711629.aspx
    UnprepareHeader http://msdn2.microsoft.com/en-us/library/ms711641.aspx)
    [Note: The full code for what I want to do can be found here http://www.borg.com/~jglatt/tech/lowmidi.htm (section "outputting system exclusive MIDI messages) - basically I need a translation of this code to LabView.]
    The following are my problems:
    a) How do I emulate a struct in LabView? (other threads suggest that this is done by clusters)
    b) How do I pass a pointer to a struct (cluster?) to a DLL?
    c) If I can use a cluster for this struct, how do I represent the LPSTR lpData in the cluster, i.e., a pointer to my data?
    d) how do I get the struct size for cbMidiOutHdr?
    This is how far I got, lots of it with the help of several threads in this forum:
    a) use a LabView cluster
    b) use "adapt to type" in the dll call (couldn't get this to work)
    c) I use a type cast on my string in the hope that what it returns is the register address (and I'm probably superwrong here)
    d) my cluster consists of 9 elements of 4 byte datatypes, so I just use 36 for cbMidiOutHdr
    The dll seems to be happy with the way I pass the cluster - I get error codes of 0 in both the PrepareHeader and UnprepareHeader functions. However, sending doesn't work (error code 7). Guessing that the type cast returns a pointer, I have also cast the cluster to an Int32 and passed that parameter as pointer to numeric value. Interestingly, the PrepareHeader and UnprepareHeader functions are still happy, but I get a different error code from the sending (code 11)
    Most of what I've done so far is guesswork, and I'm out of guesses now. I've attached the code to this post (it uses VIs from the NI MIDI example library ftp://ftp.ni.com/pub/devzone/epd/midi-example.llb ). I'd appreciate any help with this. Thanks!
    Attachments:
    Write MIDI SysEx Message.vi ‏21 KB

    First off, this problem doesn't have anything to do with control references; those have meaning only inside of the LabView environment.
    My first suggestion is to look for a higher-level library that will do whatever MIDI function you are trying to call. If you can find an ActiveX or .NET object that will control the MIDI subsystem, I recommend that you use it instead since it will be a lot easier.
    If calling the DLL directly is the best option (and calling DLLs is absolutely the way to go when you need high performance) then you need to understand how LabView passes data to library functions. That is described here:
    http://zone.ni.com/reference/en-XX/help/371361D-01/lvexcodeconcepts/configuring_the_clf_node/
    As you can see there are a lot of ways to pass data, but they boil down to this: LabView can pass, via various levels of dereferencing, a pointer to some [mostly] flat data. Things are easiest when your DLL mimics LabView's own data storage methods. For example, wiring a cluster into a node set with Adapt to Type passes a handle (struct**, pointer to pointer to [mostly] flat data). So if you are writing your own DLL, it's pretty easy to write something that works nicely with LabView data (e.g., strings with 4-byte length headers, self-describing arrays) and in fact the result is cleaner looking than its "pure C" variant because of the self-describing arrays and string length prefixes. (I say "mostly" flat because LabView clusters with variable-length elements aren't stored in a flat format.)
    When it comes to matching someone else's API things get harder, and in this case you are out of luck; you are going to have to write a LabView-callable wrapper function in C because LabView can't mimic the exact data structure needed. The problem is not the struct; there is a sneaky way to pass a pointer (vs a handle) to a struct, which is to do this:
    Generate a cluster in LabView representing the struct (atomic numeric data only! no strings arrays etc!)
    Flatten to string using native byte order.
    Convert string to byte array.
    Configure the call library function note to accept a pointer to an unsigned byte array. (NOT a C-string as suggested at the bottom of the page in the link above; your data may have internal 0x00s, and it certainly doesn't need an extra 0x00 at the end!)
    The reason this works is that a pointer is just an address; as long as all the right bytes are in memory in the right order starting at that address, all is well. The DLL doesn't know that LabView thinks it is passing a pointer to an array of bytes, it just gets the pointer to the first byte and it reads and interprets those bytes according to its own struct def. Reverse the process cooming back from the DLL (convert byte array to string, unflatten from string against the LV cluster.) This method will work for any flat struct.
    In LabView 8.5 there may be a less bogus way of doing this, which is to pass the cluster in with Adapt to Type and select "Array Data Pointer" as the format. This is new and I haven't tried it.
    But in your case, you want to point to a struct that contains a pointer to a string plus some numeric data and another pointer, and this you can't do directly. LabView does not expose the location of a string to you anywhere outside the Call Library Function node, so there's no way to "find the pointer" to a LabView string from outside the DLL. What you need to do in this case is write a wrapper function in C that takes your LabView data. Only then will LabView "tell you where the bytes are" and promise not to fiddle with them until the library call is complete. Once you are in C-land, you can throw pointers around to your heart's content. As long as you do it all perfectly, all will be well. (If you write one byte too many on output, boom! :-)
    There are a few ways to do this. You could make a cluster that has meaning in LabView, e.g. replace lpData with a LabView string, then pass the cluster in to your wrapper function set to "Adapt to Type"; that will pass a handle to the cluster. You can generate the .c file from the Call Lib Fuction, and it will outline where the data is.
    Complications: In this case it's your job to convert the handle to the labview string (which has 4 bytes of length as a prefix and no trailing 0x00) to a C-string by malloc()'ing a new buffer and memcopying the string out. There might be something in the LV CIN tools that does this, I'm not sure. Make sure you release the new string after the MIDI call.
    The lazy route (which is what I would do) is pass the string as the first arg and all of the numeric stuff as the second arg, leaving the space for lpData as you have now. (I don't know what struct "midihdr_tag" is, but if that's not something you were passed in a previous call, you'll need to add a third argument for that cluster and treat it similarly.) Then you can tell LabView that it should pass the string arg as a C-string pointer. Inside your wrapper, extract the pointers and stuff them into the data structure as needed. Dereference once (to go from handle to pointer) and make the MIDI call. To be clean, put everything back where it was before in the cluster; in particular don't believe you can pass out lpData* and do whatever you want with it in LabView; LabView will release/change that address as soon as you leave the output string unwired or do anything to it (e.g. concatenate.) You'll be creating a new string buffer and a new pointer on your next MIDI call.
    All of this complication is a result of a) LabView's hiding the details of memory allocation/deallocation from you and b) LabView's internal data structures being a bit different from C conventions (e.g. LabView strings vs. C strings). The second means that even when LabView is using non-flat data structures (e.g. cluster containing an array), you can't just blindly pass them along to a C function and expect it to work right. It would be nice if NI would write a little mini-compiler into the Call Library Function that would do what our wrapper function is going to do, but that's probably a fairly significant project. 
    Still, each function wrapper is only going to have about 10 lines of C. You can put wrappers for all the MIDI functions you want to call into a single DLL, then ship that DLL with your app.
    (Now you see why I suggested you look for an ActiveX MIDI control!)
    -Rob Calhoun

  • 10gR2 problems

    Hello
    I was previously working on OWB 9.2 and recently have joined a project which uses OWB 10gR2..
    Now as i have started working on the same, i am getting a lot of issues in 10gR2 which i hadn't faced in 9.2 version...
    One scenario is:
    We were having some problems in our Development database, so we shut the database and restarted the same. As per the convention, the jobs that were running before shutting down of the database, should get killed and resources should be released. But that is not the case.. the jobs are still running and it hasn't relaesed any of the resources.
    Second scenario is :
    Whenever I login to Runtime Audit Browser to see audit details.. After refreshing any thing, the page again is thrown back to Login page or comes back on login page where in I have to give the login details again.
    I just want to know what are the enhancements of 10gR2 over 9.2 versions and what are the drawbacks??
    Thanks

    There appear to be lots of errors involved.
    gsdctl does not work because it switches the oracle home to db_1 but then calls db_1/bin/lsnodes which does not exist (try crs_1/bin/lsnodes? or one of the others?).
    lsnodes is built in many places, and most have some bug causing the "struct size 0". I tried some workarounds with varied success, but nothing worked 100%.
    Finally, I did what you did, e.g.
    ./srvctl status nodeapps -n "<hostname>"
    crs_stop -all
    ./srvctl stop nodeapps -n "<hostname>"
    ./srvctl start nodeapps -n "<hostname>"
    crs_start -all
    ./srvctl start database -d "<sid>"
    which is almost as simple as "crs_start -all", but I'm hesitant to put this in my boot procedure because I'd have to figure out how long to wait.
    Nice to see that even less testing is going into 10gR2. ;-)
    Mike

  • Symbols for wmp.dll on Windows 8.1?

    Hi, I'm trying to load the debugging symbols for wmp.dll on Windows 8.1, but the symchk output shows that they don't exist on the Microsoft symbol server (see below). I've also installed the Windows 8.1 x86 32-bit retail symbols from
    here, but that doesn't contain the wmp.dll symbols either. Is this an oversight from Microsoft's side, or am I doing something wrong or looking in the wrong places?
    Thanks!
    C:\Program Files\Windows Kits\8.1\Debuggers\x86>symchk c:\Windows\System32\wmp.d
    ll -v
    [SYMCHK] Searching for symbols to c:\Windows\System32\wmp.dll in path SRV*C:\WIN
    DOWS\SYMBOLS*http://msdl.microsoft.com/download/symbols
    DBGHELP: Symbol Search Path: SRV*C:\WINDOWS\SYMBOLS*http://msdl.microsoft.com/do
    wnload/symbols
    [SYMCHK] Using search path "SRV*C:\WINDOWS\SYMBOLS*http://msdl.microsoft.com/dow
    nload/symbols"
    DBGHELP: No header for c:\Windows\System32\wmp.dll.  Searching for image on disk
    DBGHELP: c:\Windows\System32\wmp.dll - OK
    SYMSRV:  File: wmp.pdb
    SYMSRV:  Notifies the client application that a proxy has been detected.
    SYMSRV:  Connecting to the Server: http://msdl.microsoft.com/download/symbols.
    SYMSRV:  Successfully connected to the Server.
    SYMSRV:  Sending the information request to the server.
    SYMSRV:  Successfully sent the information request to the server.
    SYMSRV:  Waiting for the server to respond to a request.
    SYMSRV:  Successfully received a response from the server.
    SYMSRV:  Closing the connection to the Server.
    SYMSRV:  Successfully closed the connection to the Server.
    SYMSRV:  Get File Path: /download/symbols/wmp.pdb/F3B83C13024549F7A128285E604D07
    082/wmp.pdb
    SYMSRV:  Notifies the client application that a proxy has been detected.
    SYMSRV:  Connecting to the Server: http://msdl.microsoft.com/download/symbols.
    SYMSRV:  Successfully connected to the Server.
    SYMSRV:  Sending the information request to the server.
    SYMSRV:  Successfully sent the information request to the server.
    SYMSRV:  Waiting for the server to respond to a request.
    SYMSRV:  Successfully received a response from the server.
    SYMSRV:  Closing the connection to the Server.
    SYMSRV:  Successfully closed the connection to the Server.
    SYMSRV:  Notifies the client application that a proxy has been detected.
    SYMSRV:  Connecting to the Server: http://msdl.microsoft.com/download/symbols.
    SYMSRV:  Successfully connected to the Server.
    SYMSRV:  Sending the information request to the server.
    SYMSRV:  Successfully sent the information request to the server.
    SYMSRV:  Waiting for the server to respond to a request.
    SYMSRV:  Successfully received a response from the server.
    SYMSRV:  Closing the connection to the Server.
    SYMSRV:  Successfully closed the connection to the Server.
    SYMSRV:  Get File Path: /download/symbols/wmp.pdb/F3B83C13024549F7A128285E604D07
    082/file.ptr
    SYMSRV:  Notifies the client application that a proxy has been detected.
    SYMSRV:  Connecting to the Server: http://msdl.microsoft.com/download/symbols.
    SYMSRV:  Successfully connected to the Server.
    SYMSRV:  Sending the information request to the server.
    SYMSRV:  Successfully sent the information request to the server.
    SYMSRV:  Waiting for the server to respond to a request.
    SYMSRV:  Successfully received a response from the server.
    SYMSRV:  Closing the connection to the Server.
    SYMSRV:  Successfully closed the connection to the Server.
    SYMSRV:  C:\WINDOWS\SYMBOLS\wmp.pdb\F3B83C13024549F7A128285E604D07082\wmp.pdb no
    t found
    SYMSRV:  http://msdl.microsoft.com/download/symbols/wmp.pdb/F3B83C13024549F7A128
    285E604D07082/wmp.pdb not found
    DBGHELP: wmp - no symbols loaded
    [SYMCHK] MODULE64 Info ----------------------
    [SYMCHK] Struct size: 1680 bytes
    [SYMCHK] Base: 0x10000000
    [SYMCHK] Image size: 13377536 bytes
    [SYMCHK] Date: 0x5450386d
    [SYMCHK] Checksum: 0x00cc1977
    [SYMCHK] NumSyms: 0
    [SYMCHK] SymType: SymNone
    [SYMCHK] ModName: wmp
    [SYMCHK] ImageName: c:\Windows\System32\wmp.dll
    [SYMCHK] LoadedImage: c:\Windows\System32\wmp.dll
    [SYMCHK] PDB: ""
    [SYMCHK] CV: RSDS
    [SYMCHK] CV DWORD: 0x53445352
    [SYMCHK] CV Data:  wmp.pdb
    [SYMCHK] PDB Sig:  0
    [SYMCHK] PDB7 Sig: {F3B83C13-0245-49F7-A128-285E604D0708}
    [SYMCHK] Age: 2
    [SYMCHK] PDB Matched:  TRUE
    [SYMCHK] DBG Matched:  TRUE
    [SYMCHK] Line nubmers: FALSE
    [SYMCHK] Global syms:  FALSE
    [SYMCHK] Type Info:    FALSE
    [SYMCHK] ------------------------------------
    SymbolCheckVersion  0x00000002
    Result              0x00010001
    DbgFilename         wmp.dbg
    DbgTimeDateStamp    0x00000000
    DbgSizeOfImage      0x00000000
    DbgChecksum         0x00000000
    PdbFilename         wmp.pdb
    PdbSignature        {F3B83C13-0245-49F7-A128-285E604D0708}
    PdbDbiAge           0x00000002
    [SYMCHK] [ 0x00000000 - 0x00010001 ] Checked "c:\Windows\System32\wmp.dll"
    SYMCHK: wmp.dll              FAILED  - wmp.pdb mismatched or not found
    SYMCHK: FAILED files = 1
    SYMCHK: PASSED + IGNORED files = 0
    Tim De Baets
    http://www.bm-productions.tk

    Yes, it looks like the matching pdb for your version of wmp.dll is missing on the MS-symbol-server. Could be a glitch on their side.
    Symbols in 'Windows symbol packages' include sometimes 'outdated' symbol files, (PDB-Signatures of pdb and module differ).
    If symbols for certain modules are missing altogether in these packages, MS may not have the intention to publish them for reason of intellectual property. (Personal opinion).
    In any case, to my knowledge, the team in charge of public-symbols - at least for system modules (hmm, wmp is media player ...) - can be contacted via  
    windbgfb [at] microsoft [dot] com
    see
    https://social.msdn.microsoft.com/Forums/lync/en-US/f5408a35-f097-4006-9c95-bf1802d03ead/no-symbols-for-ntdlldll-on-microsofts-symbol-server-kb2882822?forum=windbg
    With kind regards
    Edit: wording
    Just see, for Vista symbols for wmp.dll are available through public-symbol-server, though
    call themselves wmp_notestroot.pdb

  • CVI2010 sizeof-operator returns a wrong size of a struct

    Hi,
    in CVI2010 the sizeof-operator returns a wrong size of a struct, if it contains 4 bytes and other spaces. I suppose the adresses in the struct are also not like a c-programmer thinks. First a minimalistic code-example:
    typedef struct
      char oneByte;
      long fourByte;
    } TestStruct;
    void main( )
        int size;
        TestStruct tmpVar;
        size = sizeof( TestStruct );
        // here is size=8 instead of 5
    Since the last years and the last cvi-versions i had ever compiled
    with the Borland-compiler, that returns the correct size. Because in CVI 2010 the Borland-compiler is
    not included, i'm trying to use the standard build-In compiler. In my opinion the compiler seems to optimize the code in a way, my
    project can't work with.
    Because i'm reading the struct direct out of binary files i'm searching for a, not code based, solution.
    Is it possible to deactivate the relevant optimization?
    Thanks for your help and answer.
    Markus
    Solved!
    Go to Solution.

    The compiler can have different alignments for struct fields: a usual behaviour is to have them aligned on a 4-byte boundary, that is every field starts on a multiple of 4 bytes from the beginning of the struct in memory. This appears to be the behaviour of the compiler you are using at the moment, which returns 8 as the size of the struct having aligned the fields.
    Struct alignment can be modified with an appropriate #pragma preprocessor instruction: adding #pragma pack (1); in your code instructs the compiler to pack structure fields without padding; after this instruction sizeof  will return the 5-bytes dimension you are expecting.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • How do I pass an array of structs to a C function using the dll flexible prototype adapter?

    What I want to do is pass into a C dll function a variably sized Array of structs of type TPS_Data. My Code compiles but when I run it in TestStand, I get an error -17001; Program Error. "Cannot allocate 0 size buffer Error in parameter 2, 'OpenFrdData'."
    I've allocated the Array of structs, and all of the information is there before I call my function, so is it my prototype? Or am I asking too much of the DLL Flexible Prototype Adapter to pass an Array of Structs?
    I can pass in a single struct of type TPS_Data and that works, but not an array.
    Here's the relevent code:
    typedef struct TPS_DATA
    char Report_Number[256];
    char System_Name[256];
    char Open_Date[256];
    char UUT_Part_Number[256];
    char UUT_Serial_Number[256];
    char UUT_Name[256];
    char Open_Employee_Name[256];
    char Open_Employee_Number[256];
    char Close_Employee_Name[256];
    char Close_Employee_Number[256];
    char Close_Date[256];
    } TPS_Data;
    typedef struct TPS_DATA_ARRAY
    TPS_Data DataRecord;
    } TPS_DataArray;
    long __declspec(dllexport) __stdcall OpenDialog (CAObjHandle Context, TPS_DataArray *TpsData[], const char *psFaultStr, char *sComments, const int nCount);

    OK,
    I can pass the data to the DLL function, using the following types:
    typedef struct StringArrayType
    char string[10][256];
    } StringArray;
    typedef struct MultiStringArrayType
    StringArray Record[10];
    } MultiStringArray;
    void __declspec(dllexport) __stdcall ATP_TestStructPassing(StringArray Strings)
    return;
    void __declspec(dllexport) __stdcall ATP_TestMultiStructPassing(MultiStringArray *Strings)
    return;
    But when the MultiStruct function Exits, TestStand reports an Error:
    -17501 "Unexpected Operating System Error" Source: 'TSAPI'
    There doesn't seem to be a way around this, and once the error occurs, I have to force quit TestStand. I've included the sequence file, and the dll code can be compiled from the fun
    ctions shown above.
    Any thoughts on how to get around this error would be greatly appreciated.
    Attachments:
    StructArrayPassing.seq ‏16 KB

  • Odd compile errors using a struct in a vector

    I am following Accelerated C++ by Koenig and Moo to learn C++, using Eclipse as my IDE and the MinGW tool chain. Chapter 4 teaches about the struct concept using a pretty simple multi-file example program which emulates reading in a series of student grades and outputs the averages. The struct it defines is called Student_info. Here is Student_info.h:
    #ifndef STUDENT_INFO_H_GUARD
    #define STUDENT_INFO_H_GUARD
    #include <iostream>
    #include <string>
    #include <vector>
    struct Student_info {
    std::string name;
    double midterm, final;
    std::vector<double> homework;
    bool compare(const Student_info&, const Student_info&);
    std::istream& read(std::istream&, Student_info);
    std::istream& read_hw(std::istream&, std::vector<double>&);
    #endif /* STUDENT_INFO_H_GUARD */
    There are no errors associated with compare, read or read_hw.
    The problem I am having is that even though the simple variable declaration below seems to work,
    #include "Student_info.h"
    int main() {
    vector<Student_info> students;
    Student_info record;
    string::size_type maxlen = 0;
    in the sense that the Eclipse code editor signals via i) its color coding that it has found the data type; ii) when I mouseover, it shows me the underlying Student_info definition in the hover box; and iii) the code associated with the variable "record" doesn't generate errors.
    However, when I try to use the students vector within main(), I get 'could not be resolved' errors on the property names or 'invalid arguments' for functions which try to pass the variables. For example,
    for(vector<Student_info>::size_type i=0; i!=students.size(); ++i) {
    cout << students[i].name
    << string(maxlen+1 - students[i].name.size(), ' ');
    produces a "Method 'size' could not be resolved" error and a "Field 'name' could be resolved" error.
    It's very odd to me, as I said, because mouseover of the vector students declaration at the beginning of main() produces a hover box with the correct struct definition, indicating the include file is being found and contains the intended definition with the 'name' property defined as a string.
    I've been trying to solve this for a couple of days and have searched the web and this site, as well as going over all the code many times. The code seems to be exactly what is in the book and it's not too difficult to figure out what it is supposed to be doing. I haven't been able to find a similar error description here or elsewhere by Googling. These errors prevent the project from compiling and so I can't precede. I'm hoping someone can describe what might possibly cause such a thing.
    Here's a shortened version of the file with main in it:
    #include <algorithm>
    #include <iomanip>
    #include <ios>
    #include <iostream>
    #include <string>
    #include <vector>
    #include <stdexcept>
    #include "Student_info.h"
    //say what standard library names we use
    using std::cin; using std::setprecision;
    using std::cout; using std::sort;
    using std::domain_error; using std::streamsize;
    using std::endl; using std::string;
    using std::max; using std::vector;
    int main() { // begin main
    vector<Student_info> students;
    Student_info record;
    string::size_type maxlen = 0;
    //read and store all the records, and find the length
    // of the longest name
    while(read(cin, record)) {
    maxlen = max(maxlen, record.name.size());
    students.push_back(record);
    //alphabetize the records
    sort(students.begin(), students.end(), compare);
    for(vector<Student_info>::size_type i=0; i!=students.size(); ++i) {
    // write the name, padded on the right to maxlen+1 chars
    cout << students[i].name
    << string(maxlen+1 - students[i].name.size(), ' ');
    //compute and write the grade
    cout << endl;
    return 0;
    } // end main
    Here are the 'read' functions, which are in a separate file from main and don't seem to be producing any errors:
    #include "Student_info.h"
    using std::istream; using std::vector;
    istream& read_hw(istream& in, vector<double>& hw) {
    if (in) {
    // get rid of previous contents
    hw.clear();
    // read homework grades
    double x;
    while (in >> x)
    hw.push_back(x);
    // clear the stream so that input will work for the
    // next student
    in.clear();
    return in;
    istream& read(istream& is, Student_info s) {
    // read and store the student's name and midterm and final exam
    is >> s.name >> s.midterm >> s.final;
    read_hw(is, s.homework);
    return is;
    bool compare(const Student_info& x, const Student_info& y) {
    return x.name < y.name;
    }

    Do you mind to try:
    for(unsigned i=0; i < students.size(); ++i)
    instead of :
    for(vector<Student_info>::size_type i=0; i!=students.size(); ++i)

  • How to get the size of the cuurrent illustration

    Sorry, I made a mistake before this one. The questios is this: can anybody tell me how can I get the size of the current illustration, (as oposed to the page size) in points. Something like 120 points wide and 87 points High?. What function do I need to call?

    From AI Function reference (included with CS2 SDK):
    AIDocumentSetup setup;
    error = sDocument->GetDocumentSetup(&setup);
    if (error) goto processError;
    writeDocumentSetup( &setup );
    The AIDocumentSetup record returns the following information:
    typedef struct {
    AIReal width, height;
    AIBoolean showPlacedImages;
    short pageView;
    AIReal outputResolution;
    AIBoolean splitLongPaths;
    AIBoolean useDefaultScreen;
    AIBoolean compatibleGradients;
    AIBoolean printTiles;
    AIBoolean tileFullPages;
    } AIDocumentSetup;

  • How to pass a struct to a DLL function and accessing it in another VI

    Hi friends,
                       I am new to labview. I need to create a demo program in labview ,for displaying image from our own image capturing system. We have a  DLL ( build in VC++) containing functions for capturing image from our system. Now I need to create a VI library for some of functions in DLL and Create a Demo program using those created subvi library . I used "Call Function node" and created some of subvi's.
     Some of our DLL functions need to pass struct pointers.  Our function prototype will be similar to the following function.
    __declspec(dllexport) int __stdcall Initialize( unsigned char *imagebuffer,struct config *Configuration);
    The passed struct is similar to
    struct config
      double                val1[3];
      unsigned short   val2;
      bool                    val3;
      bool                    val4[3];    
      unsigned char    val5;    
      unsigned char   val6[3];
      bool                    val7[26];
    For passing "unsigned char *imagebuffer"  I initialized array with "Numeric constant " and set the size of the array and send to the function.
    The problem here is, I used this array in one of the subvi. 
    How can I use the returned imagebuffer array  in my main demo program. How to connect the image array to subvi "Connecter Pane"
    And  which control  can I use to display the image. The image data I get is form of 1-D Array .
    The second problem is,
                                 For passing the structure,  I used "Bundle " and filled the bundle with all the datatypes as in my struct and passed to the function. Is it correct ?  How to access this bundle after returned from function  in another Vi. ie.) How to connect this bundle to the connter pane ?
    Thanks for your valuable suggestions.
    aajjf.
    Message Edited by aajjf on 04-19-2007 05:34 AM

    aajjf wrote:
    Hi friends,
                       I am new to labview. I need to create a demo program in labview ,for displaying image from our own image capturing system. We have a  DLL ( build in VC++) containing functions for capturing image from our system. Now I need to create a VI library for some of functions in DLL and Create a Demo program using those created subvi library . I used "Call Function node" and created some of subvi's.
     Some of our DLL functions need to pass struct pointers.  Our function prototype will be similar to the following function.
    __declspec(dllexport) int __stdcall Initialize( unsigned char *imagebuffer,struct config *Configuration);
    The passed struct is similar to
    struct config
      double                val1[3];
      unsigned short   val2;
      bool                    val3;
      bool                    val4[3];    
      unsigned char    val5;    
      unsigned char   val6[3];
      bool                    val7[26];
    For passing "unsigned char *imagebuffer"  I initialized array with "Numeric constant " and set the size of the array and send to the function.
    The problem here is, I used this array in one of the subvi. 
    How can I use the returned imagebuffer array  in my main demo program. How to connect the image array to subvi "Connecter Pane"
    And  which control  can I use to display the image. The image data I get is form of 1-D Array .
    The second problem is,
                                 For passing the structure,  I used "Bundle " and filled the bundle with all the datatypes as in my struct and passed to the function. Is it correct ?  How to access this bundle after returned from function  in another Vi. ie.) How to connect this bundle to the connter pane ?
    Thanks for your valuable suggestions.
    aajjf.
    Message Edited by aajjf on 04-19-2007 05:34 AM
    You say nothing about how your cluster looks but I'm afraid you did the standard error here and placed arrays in it. That is not what the C structure is representing for several reasons.
    First fixed size arrays in C are inlined inside a structure, so are not a pointer but for the case of your val1 element three doubles.
    Second although not relevant here because of above point: LabVIEW arrays are not the same as C arrays. LabVIEW uses a pointer to a pointer and has the size of the array in elements prepended to the array data. C simply uses a pointer and all the rest is the programmers sorrow. The Call Library Node does convert the top level element of variables you pass according to the type configuration of that parameter but does no conversion of internal elements at all. So passing clusters with anything like arrays or strings is always wrong unless the DLL is aware of the specific datatypes LabVIEW uses.
    Last but not least you can end up with alignment issues. Elements in structures are aligned by every C compiler to a certain value. This value can be defined by the programmer in the project settings or for Visual C through #pragma pack() statements in the C code. The alignment rule says that an variable is aligned to the smaller of the two values that are either a multiple of the variable element size or the alignment setting. Most 32bit code nowadays uses 8 bit default alignment but LabVIEW always uses 1 byte. In your case there is nothing to observe since the large variables are at the beginning. Otherwise you might have had to insert filler elements in the LabVIEW cluster.
    One last thing bool is a C++ type only. Its size is 1 byte and incidentially this is the same LabVIEW uses for Booleans.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Reduce File Size functionality

    Hi,
                I want to automate the Reduce File Size functionality available in acrobat in one of my plug-in application. This is because,
                          Earlier I used "PDDocSaveWithParams" to set the PDF file version as per user selection, but it was failing many times to set PDF Version to lower versions.  So later I did the following change.
                I used "AVDocSaveOptimized" to set the PDF to the user selected version(It may be to a lower or to a higher version).  It was working fine.  but later when it is used on acrobat Standard version. It is failing to do the same, as "PDF Optimizer" is abesent in Standard.
                I need to find an alternative to set the compatible PDF version, which works on both Standard and professional.   So if I am able to automate the Reduce File Size funciton from acrobat window, it will set the PDF version of the file to the user selection.  Can anybody tell me, how can i use it?  if it is through AVCommand, then which is that command.  
            If not, what alternative i can use to set the PDF version of the file to the user selection?
             Please help me,
    your help would be highly appreciated.
    palaksha Nyamathi

    But the in that funciton
    it is working fine on Acrobat Professional, but the same without any changes (and for the same set of PDF files),
    it is crashing on Acrobat Standard.    I don't know what's going wrong here.  I have just added code part below,  Can you tell me, where it is creating problem and what's remedy for this?
        if(iAVersion == 0) iAVersion = kPDFOptRetainVersion;
        else if(iAVersion == 4) iAVersion = kPDFOptAcrobat5;
        else if(iAVersion == 5) iAVersion = kPDFOptAcrobat6;
        else if(iAVersion == 6) iAVersion = kPDFOptAcrobat7;
        PDFOptFlattenTransparencyOptions trnsOpts;
        trnsOpts = (struct _t_PDFOptFlattenTransparencyOptions*)malloc(sizeof(PDFOptFlattenTransparencyOptionsRec));
        trnsOpts->size = sizeof(PDFOptFlattenTransparencyOptionsRec);
        trnsOpts->pctRasterVectorBalance = 75;
        trnsOpts->ppiLineArtAndText = 300;
        trnsOpts->ppiGradientAndMesh = 150;
        trnsOpts->bConvertText = false;
        trnsOpts->bConvertStrokes =  true;
        trnsOpts->bClipComplexRegions  = true;
        trnsOpts->bPreserveOverprint = true;
        PDFOptImageOptionsRec imageRec;
        imageRec.size = sizeof(PDFOptImageOptionsRec);
        imageRec.enmDownsamplingAlgo = kPDFOptBicubic;
        imageRec.ppiDownsampleTo = 150;
        imageRec.ppiDownsampleAbove = 225;
        imageRec.enmCompressionAlgo = kPDFOptJpeg;               
        imageRec.enmCompressionQlty = kPDFOptMediumQlty; 
        imageRec.nTileSize = 1024;  
        PDFOptParamsRec optParam;
        optParam.size = sizeof(PDFOptParamsRec);
        //Changes for defect 11853. palaksha  
        optParam.asPathDest = ASFileSysCreatePathName( ASGetDefaultFileSys(), ASAtomFromString("Cstring"), OLE2A(csfile), NULL );
        optParam.fileSys = NULL;
        optParam.progMon = NULL;
        optParam.progMonClientData= NULL;
        optParam.enmAcrobatVersion =  iAVersion;
        optParam.imageOptionsColor = imageRec;                           
        optParam.imageOptionsGrayscale = imageRec;                     
        imageRec.ppiDownsampleTo = 300;
        imageRec.ppiDownsampleAbove = 450;
        imageRec.enmCompressionAlgo = kPDFOptCCITT4;
        optParam.imageOptionsMonochrome  = imageRec;          
        optParam.arrPDFontsToUnembed = NULL;       
        optParam.cPDFontsToUnembed =0;       
        optParam.pdfOptFlattenTransparencyOptions = trnsOpts;    
        optParam.bRemoveFormActions = false;
        optParam.bFlattenFormFields = false;        
        optParam.bRemoveJavascriptActions = false;
        optParam.bRemoveAlternateImages = true;
        optParam.bRemoveThumbnails = false;
        optParam.bRemoveDocumentTags = false;
        optParam.bSmoothenLines = false;       
        optParam.bMergeImageFragments = false;
        optParam.bRemovePrintSettings = true;
        optParam.bRemoveSrchIndex = false;
        optParam.bRemoveBookmarks = false;
        optParam.bRemoveCommentsAndWidgets = false;
        optParam.bRemoveDocInfoAndMetadata = false;
        optParam.bRemoveObjectData = false;
        optParam.bRemoveFileAttachments = false;
        optParam.bRemoveCrossRefs = false;
        optParam.bRemovePrivateData = false;
        optParam.bFlattenVisibleLayers = true;
        optParam.enmObjectCompression = kPDFOptPartialCompression;
        optParam.bUnencodedToFlate = false;
        optParam.bLZWToFlate = true;
        optParam.bRemoveInvalidBookmarks = false;
        optParam.bRemoveInvalidLinks  = false;
        optParam.bRemoveUnreferencedNamedDests = false;
        optParam.bLinearize = true;
        optParam.bSkipIrreducibleImages = true ;
           CString csFileName = "";
        bOptimize = true;
        AVDocSaveOptimized (avDoc, &optParam);
    thanks for you help,
    palaksha

  • How to deal with variable length data struct in C/JNI

    I have another JNI related question. How do you handle variable length
    data structures in Java and pointer to a pointer?
    Basically, I have a backend in C which has records but we don't know
    how many. The API looks like
    typedef struct rec_list_s {
    int rec_list_cnt;
    rec_list_data_t rec_list_data[1];
    } rec_list_t;
    int rec_list_show(void handle, rec_list_t *list_ptr);
    /* Code snippet for rec_list_show */
    int rec_list_show(void handle, rec_list_t *list_ptr)
    rec_list_t *ptr;
    sz = sizeof (rec_list_t) +
    ((record_count - 1) * sizeof (rec_list_data_t));
    ptr = malloc(sz);
    /* fill the data */
    *list_ptr = ptr;
    return (0);
    So I need to wrap rec_list_show() in JNI call so I can have Java call
    it. How do i pass a pointer to a pointer from Java? I tried in the
    native C code for JNI to return the pointer to pointer as a result
    and store in a member in the Java class rec_list_t and then I pass
    that to JNI call for rec_list_show. The C backend code was fine
    since it got the pointer to pointer but Java become unhappy when
    the object it was referencing changed memory location (I suspect
    the garbage collection becomes unhappy).
    So what would be a good way to deal with this kind of code?
    Thanks,
    Sunay
    Edited by: st9 on Aug 30, 2010 5:47 PM

    I did not imply that you don't know C but you are implying that I don't understand C. Perhaps
    google Sunay Tripathi and click I am feeling lucky so that we don't get into teaching C
    discussions :) On the other hand, I am definitely looking for someone to teach me Java
    otherwise I wouldn't be asking.
    Anyway, let me explain again. The sample function rec_list_show() runs on the backend. It
    is a different process with a different VM space. It of course knows the size of the array
    and what to fill in. As a caller to that API (which is a separate process), I don't know
    what that size is but I need to get the size and corresponding data in one shot because
    the backend locks the table when its providing me the info to make sure its synchronous.
    Now I (the Java process) needs to get that count and data in one shot. Since the C library
    underneath me (wrapped around my JNI interface) has private IPC mechanism to copy
    the contiguous memory from the backend into my memory space, all I need is to provide
    a pointer to a pointer which gets filled in by backend and is available to my process. So
    my equivalent C frontend just passes a pointer to a pointer and casts the return value in
    rec_list_t. The rec_list_cnt tells it how many members it got. The first member is part of
    the struct itself but then following members are right after.
    Another way to help you understand this is with this code snippet from front end C program
    rec_list_t     *ptr, *save_ptr;
    rec_list_data_t *data_ptr;
    int          cnt;
    save_ptr = ptr = malloc(sizeof(rec_list_t));
    rec_list_show(handle, &ptr);
    assert(save_ptr != ptr);
    cnt = ptr->rec_list_cnt;
    for (i = 0; i < cnt; i++) {
         data_ptr = &ptr->rec_list_data;
    Notice the assert(). Also notice the for loop. How do I expect to walk more that one
    member when rec_list_data is a fixed size array of one member?typedef struct rec_list_s {
         int               rec_list_cnt;
         rec_list_data_t          rec_list_data[1];
    } rec_list_t;
    Anyway, I do understand that Java will not allow me to get a reference to a long and
    how Java memory management works. But the JNI native implementation is C
    and I was wondering if people have managed to do some tricks there between C
    and Java.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Resizing an array of struct inside a DLL using the memory manager

    Hi all,
    I dug deep inside the boards, but wasn't able to find a solution for my problem.
    I'm building a dll, which does some imageprocessing and should return an array of structs to labview, with one struct for every element in the image.
    As I don't know the number of elements beforehand and the limit of the number is numbers of magnitude larger then the expected one, I don't want to allocate such a huge chunk of memory prior to the dll call in labview.
    In a former version I used a 2d array for the elements, where each row holds the values of every element. Here I used the NumericArrayResize-function, which worked quite well. But I have to add more sub-processes and using structs (or clusters in labview) appears to be more usefull and cleaner for me, in addition I had to cast some of the elements back and foreward a few times.
    So one element-struct should hold 2 singles and 1 uint32. My question is now, how can I resize this array of struct with memory manager functions as the NumericArrayResize-functions does not suit this purpose?
    (Accessing a given array of structs inside the DLL and after that reading the changed values in Labview is surprisingly easy )
    Thanks in advance
    Solved!
    Go to Solution.

    Well, I was able to solve it myself. I found this thread, where the first post of rolfk made me thinking. It appeared to me, that the numericarrayresize-function behaves very similar to the realloc-function of c. So I used the type unsigned int 8 (which is just one byte) and multiplied it by the number of bytes used by one struct, in my case 12 bytes (4+4+4) and then multiplied it by the number of structs (elements in the image) i have. Luckily it worked and the memory block was resized exactly as I wanted it to be. Important to note: do not forget to adjust the size element of the handle, otherwise Labview does not know about the changed size.

  • Oracle sql STRUCT query

    Hi all. I have a simple program running in JDeveloper using JDBC for retrieving SDO_Geometry values from various spatial tables. The program works fine but when I run the following SQL statement to retrieve the geometry column from a table states it is returning the sdo_geometry values in the following format:
    spatialQuery = "select a.geom from states a";oracle.sql.STRUCT@e2dae9,     
    oracle.sql.STRUCT@19209ea,     
    oracle.sql.STRUCT@c8f6f8,     
    oracle.sql.STRUCT@1ce2dd4,     
    oracle.sql.STRUCT@122cdb6,     
    I know the program works but can anyone tell me how to interpret these results or even how to translate them into a more useful format. Cheers Joe

    I assume you are getting back a List (Vector) with the Struct inside it. Try ((List)query.getSingleResult()).get(0).
    In JPA you should get the Struct back directly if the result size was 1, otherwise an Object[], this was a bug in EclipseLink 1.0 that was fixed in EclipseLink 1.1.
    You should probably upgrade to EclipseLink 1.1.
    James : http://www.eclipselink.org

  • Hibernate+Spring+Structs HTTP 404 Error

    Hey,i am a new here.and a new of Java programming.I have met some problems when i begin to study this.
    And here is my problem .
    Java codes:
    HTTP Status 404 - Servlet action is not available type Status report message Servlet action is not available description The requested resource (Servlet action is not available) is not available. Apache Tomcat/5.5.25
    structs-config.xml :
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>
    <data-sources />
    <form-beans >
    <form-bean name="loginForm" type="com.yourcompany.struts.form.LoginForm" />
    </form-beans>
    <global-exceptions />
    <global-forwards />
    <action-mappings >
    <action
    attribute="loginForm"
    input="/login.jsp"
    name="loginForm"
    path="/login"
    scope="request"
    type="com.yourcompany.struts.action.LoginAction">
    <forward name="succeed" path="/welcome.jsp" />
    <forward name="fail" path="/login.jsp" />
    </action>
    </action-mappings>
    <controller>
    <set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor"/>
    </controller>
    <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
    <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" ></set-property>
    </plug-in>
    </struts-config>
    applicationContext.xml :
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <bean id="skyTest"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName"
    value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
    </property>
    <property name="url"
    value="jdbc:sqlserver://server-web:1433;databaseName=ers;">
    </property>
    <property name="username" value="ers"></property>
    <property name="password" value="123456"></property>
    </bean>
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="skyTest" />
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.SQLServerDialect
    </prop>
    </props>
    </property>
    <property name="mappingResources">
    <list>
    <value>vo/Login.hbm.xml</value></list>
    </property></bean>
    <bean id="LoginDAO" class="dao.LoginDAO">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="service" class="service.Service" singleton="false">
    <property name="loginDao">
    <ref bean="LoginDAO"/>
    </property>
    </bean>
    <bean name="/login" class="com.yourcompany.struts.action.LoginAction" singleton="false" >
    <property name="service">
    <ref bean="service"/>
    </property>
    </bean>
    </beans>
    web.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
    <param-name>debug</param-name>
    <param-value>3</param-value>
    </init-param>
    <init-param>
    <param-name>detail</param-name>
    <param-value>3</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>
    LoginDAO:
    package dao;
    import java.util.Date;
    import java.util.List;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.hibernate.LockMode;
    import org.springframework.context.ApplicationContext;
    import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
    import vo.Login;
    * Data access object (DAO) for domain model class Login.
    * @see vo.Login
    * @author MyEclipse Persistence Tools
    public class LoginDAO extends HibernateDaoSupport {
         private static final Log log = LogFactory.getLog(LoginDAO.class);
         // property constants
         public static final String EMPLOYEE_OR_CUSTOMER_ID = "employeeOrCustomerId";
         public static final String USER_NAME = "userName";
         public static final String PASSWORD = "password";
         public static final String ROLE = "role";
         public static final String CREATE_USER = "createUser";
         public static final String CHANGE_USER = "changeUser";
         protected void initDao() {
              // do nothing
         public void save(Login transientInstance) {
              log.debug("saving Login instance");
              try {
                   getHibernateTemplate().save(transientInstance);
                   log.debug("save successful");
              } catch (RuntimeException re) {
                   log.error("save failed", re);
                   throw re;
         public void delete(Login persistentInstance) {
              log.debug("deleting Login instance");
              try {
                   getHibernateTemplate().delete(persistentInstance);
                   log.debug("delete successful");
              } catch (RuntimeException re) {
                   log.error("delete failed", re);
                   throw re;
         public Login findById(java.lang.Integer id) {
              log.debug("getting Login instance with id: " + id);
              try {
                   Login instance = (Login) getHibernateTemplate().get("vo.Login", id);
                   return instance;
              } catch (RuntimeException re) {
                   log.error("get failed", re);
                   throw re;
         public List findByExample(Login instance) {
              log.debug("finding Login instance by example");
              try {
                   List results = getHibernateTemplate().findByExample(instance);
                   log.debug("find by example successful, result size: "
                             + results.size());
                   return results;
              } catch (RuntimeException re) {
                   log.error("find by example failed", re);
                   throw re;
         public List findByProperty(String propertyName, Object value) {
              log.debug("finding Login instance with property: " + propertyName
                        + ", value: " + value);
              try {
                   String queryString = "from Login as model where model."
                             + propertyName + "= ?";
                   return getHibernateTemplate().find(queryString, value);
              } catch (RuntimeException re) {
                   log.error("find by property name failed", re);
                   throw re;
         public List findByEmployeeOrCustomerId(Object employeeOrCustomerId) {
              return findByProperty(EMPLOYEE_OR_CUSTOMER_ID, employeeOrCustomerId);
         public List findByUserName(Object userName) {
              return findByProperty(USER_NAME, userName);
         public List findByPassword(Object password) {
              return findByProperty(PASSWORD, password);
         public List findByRole(Object role) {
              return findByProperty(ROLE, role);
         public List findByCreateUser(Object createUser) {
              return findByProperty(CREATE_USER, createUser);
         public List findByChangeUser(Object changeUser) {
              return findByProperty(CHANGE_USER, changeUser);
         public List findAll() {
              log.debug("finding all Login instances");
              try {
                   String queryString = "from Login";
                   return getHibernateTemplate().find(queryString);
              } catch (RuntimeException re) {
                   log.error("find all failed", re);
                   throw re;
         public Login merge(Login detachedInstance) {
              log.debug("merging Login instance");
              try {
                   Login result = (Login) getHibernateTemplate().merge(
                             detachedInstance);
                   log.debug("merge successful");
                   return result;
              } catch (RuntimeException re) {
                   log.error("merge failed", re);
                   throw re;
         public void attachDirty(Login instance) {
              log.debug("attaching dirty Login instance");
              try {
                   getHibernateTemplate().saveOrUpdate(instance);
                   log.debug("attach successful");
              } catch (RuntimeException re) {
                   log.error("attach failed", re);
                   throw re;
         public void attachClean(Login instance) {
              log.debug("attaching clean Login instance");
              try {
                   getHibernateTemplate().lock(instance, LockMode.NONE);
                   log.debug("attach successful");
              } catch (RuntimeException re) {
                   log.error("attach failed", re);
                   throw re;
         public static LoginDAO getFromApplicationContext(ApplicationContext ctx) {
              return (LoginDAO) ctx.getBean("LoginDAO");
    LoginAction :
    * Generated by MyEclipse Struts
    * Template path: templates/java/JavaClass.vtl
    package com.yourcompany.struts.action;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import com.yourcompany.struts.form.LoginForm;
    import service.Service;
    import vo.Login;
    * MyEclipse Struts
    * Creation date: 01-07-2008
    * XDoclet definition:
    * @struts.action path="/login" name="loginForm" input="/login.jsp" scope="request" validate="true"
    * @struts.action-forward name="succeed" path="/welcome.jsp"
    * @struts.action-forward name="fail" path="/login.jsp"
    public class LoginAction extends Action {  
    * Generated Methods
    * Method execute
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return ActionForward
    private Service service;
    public void setService(Service service)
    this.service=service;
    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {  
    LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
    Login login=new Login();
    login.setPassword(loginForm.getPassword());
    login.setUserName(loginForm.getUsername());
    if(service.isValid(login))
    return mapping.findForward("succeed");
    else
    return mapping.findForward("fail");
    Will you please give me some instructions.i have been hunt by this problem for many days..Thank you !
    Edited by: ChinaRose on Jan 6, 2008 10:44 PM
    Edited by: ChinaRose on Jan 6, 2008 10:47 PM

    structs-config.xmlHopefully, that's not what you actually named the file, because you refer to something different in your web.xml...
    <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>It will help you to be consistent. I recommend referring to the framework by its actual name; i.e., "Struts".
    ~

  • Can I use a struct pointer inside a struct?

    System: Red Hat Linux Enterprise 4
    BDB: 4.5.2.NC
    Language: C
    My data structure list below:
    typedef struct a
    int length;
    float area;
    }A;
    typedef struct b
    A * A1;
    int others;
    }B;
    Because the length of array A1 is various, so I want to create at run time by malloc().
    Codes list below:
    B b1;
    b1.A1 = (A*) malloc(sizeof(A)*n); /*n is set by parameter*/
    for (int i = 0; i < n; i++)
    b1.A1.length = x;
    b1.A1.area = y;
    memset(&Data, 0, sizeof(DBT));
    Data.data = &b1;
    Data.size = sizeof(B) + sizeof(A)*n;
    ret = dbp->put(dbp, NULL, &Key, &Data, DB_NOOVERWRITE);
    There was no error when putting data into BDB, but I can't get the data properly.
    ret = dbp->get(dbp, NULL, &Key, &Data, 0);
    B * b1;
    b1 = (B*)(Data.data);
    for (int j = 0; j < n; j++)
    printf("%d, %dn", b1.A1[j].length, b1.A1[j].area);
    Error appears when I access the item of array A1. : "Segementation fault"
    I got the information from DB manual ''C Getting Started Guide: Chapter 3. Database Records". It's read from the very beginning:"They can therefore be used to store anything from simple primitive data to complex structures so long as the information you want to store resides in a single contiguous block of memory."
    Does it mean that data.data can just be a block of memory? I mean that I have to specify the size of a char array (length of a string), etc.? Should not I use a dynamic size array? If could, how to do with it?

    Hi Lesslie,
    BDB stores data that is located at a specified address and of a particular size. Your data contains a field that points to dynamically allocated memory, meaning that data can be located in different, not necessarily contiguous, locations in the heap.
    To resolve this the most efficient and easiest way is to pack your data into a single memory location (a buffer that can hold your data) and then store the data in that location (this is called marshalling).
    So, you should pack the n structures of type A, and provide the Data DBT with the address of the buffer where they are marshaled and the size of the buffer holding the structures.
    For more information consult the following section in the GSG guide for C on storing structures with pointers:
    http://www.oracle.com/technology/documentation/berkeley-db/db/gsg/C/BerkeleyDB-Core-C-GSG.pdf
    Regards,
    Andrei

Maybe you are looking for