| 772 | } |
| 773 | |
| 774 | BOOL StackWalker::LoadModules() |
| 775 | { |
| 776 | if (this->m_sw == NULL) |
| 777 | { |
| 778 | SetLastError(ERROR_DLL_INIT_FAILED); |
| 779 | return FALSE; |
| 780 | } |
| 781 | if (m_modulesLoaded != FALSE) |
| 782 | return TRUE; |
| 783 | |
| 784 | // Build the sym-path: |
| 785 | char *szSymPath = NULL; |
| 786 | if ( (this->m_options & SymBuildPath) != 0) |
| 787 | { |
| 788 | const size_t nSymPathLen = 4096; |
| 789 | szSymPath = (char*) malloc(nSymPathLen); |
| 790 | if (szSymPath == NULL) |
| 791 | { |
| 792 | SetLastError(ERROR_NOT_ENOUGH_MEMORY); |
| 793 | return FALSE; |
| 794 | } |
| 795 | szSymPath[0] = 0; |
| 796 | // Now first add the (optional) provided sympath: |
| 797 | if (this->m_szSymPath != NULL) |
| 798 | { |
| 799 | strcat_s(szSymPath, nSymPathLen, this->m_szSymPath); |
| 800 | strcat_s(szSymPath, nSymPathLen, ";"); |
| 801 | } |
| 802 | |
| 803 | strcat_s(szSymPath, nSymPathLen, ".;"); |
| 804 | |
| 805 | const size_t nTempLen = 1024; |
| 806 | char szTemp[nTempLen]; |
| 807 | // Now add the current directory: |
| 808 | if (GetCurrentDirectoryA(nTempLen, szTemp) > 0) |
| 809 | { |
| 810 | szTemp[nTempLen-1] = 0; |
| 811 | strcat_s(szSymPath, nSymPathLen, szTemp); |
| 812 | strcat_s(szSymPath, nSymPathLen, ";"); |
| 813 | } |
| 814 | |
| 815 | // Now add the path for the main-module: |
| 816 | if (GetModuleFileNameA(NULL, szTemp, nTempLen) > 0) |
| 817 | { |
| 818 | szTemp[nTempLen-1] = 0; |
| 819 | for (char *p = (szTemp+strlen(szTemp)-1); p >= szTemp; --p) |
| 820 | { |
| 821 | // locate the rightmost path separator |
| 822 | if ( (*p == '\\') || (*p == '/') || (*p == ':') ) |
| 823 | { |
| 824 | *p = 0; |
| 825 | break; |
| 826 | } |
| 827 | } // for (search for path separator...) |
| 828 | if (strlen(szTemp) > 0) |
| 829 | { |
| 830 | strcat_s(szSymPath, nSymPathLen, szTemp); |
| 831 | strcat_s(szSymPath, nSymPathLen, ";"); |