IDiaSession::findLinesByLinenum
Visual Studio 2012
Determines the line numbers of the compiland that the specified line number in a source file lies within or near.
HRESULT findLinesByLinenum ( IDiaSymbol* compiland, IDiaSourceFile* file, DWORD linenum, DWORD column, IDiaEnumLineNumbers** ppResult );
The following example shows how to open a source file, enumerate the compilands contributed by this file, and locate the line numbers in the source file where each compiland starts.
void ShowLinesInCompilands(IDiaSession *pSession, LPCOLESTR filename) { IDiaEnumSourceFiles* pEnum; IDiaSourceFile* pFile; DWORD celt; pSession->findFile ( NULL, filename, nsFNameExt, &pEnum ); while ( pEnum->Next ( 1, &pFile, &celt ) == S_OK ) // for each file { IDiaEnumSymbols* pEnumCompilands; IDiaSymbol* pCompiland; pFile->get_compilands ( &pEnumCompilands ); // for each compiland while ( pEnumCompilands->Next ( 1, &pCompiland, &celt ) == S_OK ) { IDiaEnumLineNumbers* pEnum; // Find first compiland closest to line 1 of the file. if (pSession->findLinesByLinenum( pCompiland, pFile, 1, 0, &pEnum ) == S_OK) { IDiaLineNumber *pLineNumber; DWORD lineCount; while ( pEnum->Next(1,&pLineNumber,&lineCount) == S_OK) { DWORD lineNum; if (pLineNumber->get_line(&lineNum) == S_OK) { printf("compiland starts in source at line number = %lu\n",lineNum); } } } } } }
Note